Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow string values for FlagEvaluationDetails.reason and FlagResolutionDetails.reason #264

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading