Skip to content

Commit

Permalink
fix: Allow string values for FlagEvaluationDetails.reason and ``Fla…
Browse files Browse the repository at this point in the history
…gResolutionDetails.reason`
  • Loading branch information
keelerm84 committed Jan 26, 2024
1 parent d1f27e3 commit 7b86983
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions openfeature/flag_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FlagEvaluationDetails(typing.Generic[T_co]):
value: T_co
variant: typing.Optional[str] = None
flag_metadata: FlagMetadata = field(default_factory=dict)
reason: typing.Optional[Reason] = None
reason: typing.Optional[typing.Union[str, Reason]] = None
error_code: typing.Optional[ErrorCode] = None
error_message: typing.Optional[str] = None

Expand All @@ -59,6 +59,6 @@ class FlagResolutionDetails(typing.Generic[U_co]):
value: U_co
error_code: typing.Optional[ErrorCode] = None
error_message: typing.Optional[str] = None
reason: typing.Optional[Reason] = None
reason: typing.Optional[typing.Union[str, Reason]] = None
variant: typing.Optional[str] = None
flag_metadata: FlagMetadata = field(default_factory=dict)
27 changes: 27 additions & 0 deletions tests/test_flag_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ def test_evaluation_details_reason_should_be_a_string():
assert error_code == flag_details.error_code
assert error_message == flag_details.error_message
assert reason == flag_details.reason
assert isinstance(flag_details.reason, str)


def test_evaluation_details_reason_can_be_arbitrary_string():
# Given
flag_key = "my-flag"
flag_value = 100
variant = "1-hundred"
flag_metadata = {}
reason = "Non-standard reason"
error_code = ErrorCode.GENERAL
error_message = "message"

# When
flag_details = FlagEvaluationDetails(
flag_key,
flag_value,
variant,
flag_metadata,
reason,
error_code,
error_message,
)

# Then
assert reason == flag_details.reason


def test_evaluation_details_reason_should_be_a_string_when_set():
Expand All @@ -54,3 +80,4 @@ def test_evaluation_details_reason_should_be_a_string_when_set():

# Then
assert Reason.STATIC == flag_details.reason # noqa: SIM300
assert isinstance(flag_details.reason, str)

0 comments on commit 7b86983

Please sign in to comment.