Skip to content

Commit

Permalink
fix: Don't include null traits in transient identifier (#4598)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Elwell <[email protected]>
  • Loading branch information
khvn26 and matthewelwell authored Sep 9, 2024
1 parent 6714384 commit 4bf7b9d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/environments/sdk/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def get_transient_identifier(sdk_trait_data: list[SDKTraitData]) -> str:
if sdk_trait_data:
return hashlib.sha256(
"".join(
f'{trait["trait_key"]}{trait["trait_value"]["value"]}'
f'{trait["trait_key"]}{trait_value["value"]}'
for trait in sorted(sdk_trait_data, key=itemgetter("trait_key"))
if (trait_value := trait["trait_value"]) is not None
).encode(),
usedforsecurity=False,
).hexdigest()
Expand Down
2 changes: 1 addition & 1 deletion api/environments/sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class SDKTraitValueData(typing.TypedDict):

class SDKTraitData(typing.TypedDict):
trait_key: str
trait_value: SDKTraitValueData
trait_value: SDKTraitValueData | None
transient: NotRequired[bool]
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def test_get_feature_states_for_identity__segment_match_expected(
"trait_value": segment_condition_value,
},
{"trait_key": "a", "trait_value": "value_a"},
{"trait_key": "c", "trait_value": None},
],
}
),
Expand Down

0 comments on commit 4bf7b9d

Please sign in to comment.