Skip to content

fix: Get Object should return both list and dict #64

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion open_feature/flag_evaluation/flag_type.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import typing
from enum import Enum


class FlagType(Enum):
BOOLEAN = bool
STRING = str
OBJECT = dict
OBJECT = typing.Union[dict, list]
FLOAT = float
INTEGER = int
6 changes: 5 additions & 1 deletion open_feature/open_feature_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ def _create_provider_evaluation(

value = get_details_callable(*args)

if not isinstance(value.value, flag_type.value):
# we need to check the get_args to be compatible with union types.
is_right_instance = isinstance(
value.value, typing.get_args(flag_type.value)
) or isinstance(value.value, flag_type.value)
if not is_right_instance:
raise TypeMismatchError()

return value
4 changes: 2 additions & 2 deletions open_feature/provider/no_op_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def resolve_float_details(
def resolve_object_details(
self,
flag_key: str,
default_value: dict,
default_value: typing.Union[dict, list],
evaluation_context: typing.Optional[EvaluationContext] = None,
) -> FlagEvaluationDetails[dict]:
) -> FlagEvaluationDetails[typing.Union[dict, list]]:
return FlagEvaluationDetails(
flag_key=flag_key,
value=default_value,
Expand Down
4 changes: 2 additions & 2 deletions open_feature/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def resolve_float_details(
def resolve_object_details(
self,
flag_key: str,
default_value: dict,
default_value: typing.Union[dict, list],
evaluation_context: typing.Optional[EvaluationContext] = None,
) -> FlagEvaluationDetails[dict]:
) -> FlagEvaluationDetails[typing.Union[dict, list]]:
pass
12 changes: 12 additions & 0 deletions tests/provider/test_no_op_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ def test_should_resolve_string_flag_from_no_op():
assert isinstance(flag.value, str)


def test_should_resolve_list_flag_from_no_op():
# Given
# When
flag = NoOpProvider().resolve_object_details(
flag_key="Key", default_value=["item1", "item2"]
)
# Then
assert flag is not None
assert flag.value == ["item1", "item2"]
assert isinstance(flag.value, list)


def test_should_resolve_object_flag_from_no_op():
# Given
return_value = {
Expand Down
5 changes: 5 additions & 0 deletions tests/test_open_feature_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
},
"get_object_value",
),
(
list,
["string1", "string2"],
"get_object_value",
),
),
)
def test_should_get_flag_value_based_on_method_type(
Expand Down