Skip to content

Commit 3cc91be

Browse files
authored
fix: allow anything that implements str as a context property (#353)
* fix: allow anything that implements str as a context property
1 parent df37fe5 commit 3cc91be

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

UnleashClient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def _safe_context_value(self, value):
522522
return value.isoformat()
523523
if isinstance(value, (int, float)):
524524
return str(value)
525-
return value
525+
return str(value)
526526

527527
def _resolve_variant(self, feature_name: str, context: dict) -> dict:
528528
"""

tests/unit_tests/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,24 @@ def test_is_enabled_works_with_properties_field_in_the_context_root():
10441044
assert unleash_client.is_enabled("customContextToggle", context)
10451045

10461046

1047+
def test_uuids_are_valid_context_properties():
1048+
unleash_client = UnleashClient(
1049+
URL,
1050+
APP_NAME,
1051+
disable_metrics=True,
1052+
disable_registration=True,
1053+
)
1054+
1055+
context = {"userId": uuid.uuid4()}
1056+
1057+
try:
1058+
unleash_client.is_enabled("testFlag", context)
1059+
except Exception as e:
1060+
assert (
1061+
False
1062+
), f"An exception was raised when passing a UUID as a context property: {e}"
1063+
1064+
10471065
@responses.activate
10481066
def test_identification_headers_sent_and_consistent(unleash_client):
10491067
responses.add(responses.POST, URL + REGISTER_URL, json={}, status=202)

0 commit comments

Comments
 (0)