Skip to content
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
2 changes: 1 addition & 1 deletion ld_openfeature/impl/context_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __get_targeting_key(self, targeting_key: Optional[str], key: Any) -> str:
if key is not None and isinstance(key, str):
targeting_key = targeting_key if targeting_key else key

if targeting_key is None or targeting_key == "":
if targeting_key is None or targeting_key == "" or not isinstance(targeting_key, str):
logger.error("The EvaluationContext must contain either a 'targetingKey' or a 'key' and the type must be a string.")

return targeting_key if targeting_key else ""
Expand Down
10 changes: 10 additions & 0 deletions tests/impl/test_context_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def test_create_context_with_invalid_key(context_converter: EvaluationContextCon
assert caplog.records[0].message == "A non-string 'key' attribute was provided."


def test_create_context_with_invalid_targeting_key(context_converter: EvaluationContextConverter, caplog):
context = EvaluationContext(False) # type: ignore[arg-type]
ld_context = context_converter.to_ld_context(context)

assert ld_context.valid is False
assert ld_context.key == ''

assert caplog.records[0].message == "The EvaluationContext must contain either a 'targetingKey' or a 'key' and the type must be a string."


def test_invalid_private_attribute_types_are_ignored(context_converter: EvaluationContextConverter, caplog):
context = EvaluationContext("user-key", {"privateAttributes": [True]})
ld_context = context_converter.to_ld_context(context)
Expand Down