Skip to content

Commit dd17a4c

Browse files
authored
fix: Ignore embedded kind when processing multi-kind contexts (#15)
1 parent ba4e662 commit dd17a4c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

ld_openfeature/impl/context_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __build_single_context(self, attributes: Dict, kind: str, key: str) -> Conte
8383
builder.kind(kind)
8484

8585
for k, v in attributes.items():
86-
if k == 'key' or k == 'targetingKey':
86+
if k == 'key' or k == 'targetingKey' or k == 'kind':
8787
continue
8888

8989
if k == 'name' and isinstance(v, str):

tests/impl/test_context_converter.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,31 @@ def test_can_create_multi_kind_context(context_converter: EvaluationContextConve
156156
assert org_context.name == 'Org name'
157157

158158

159+
def test_can_multi_kind_ignores_kind_attribute(context_converter: EvaluationContextConverter):
160+
attributes = {
161+
'kind': 'multi',
162+
'user': {'key': 'user-key', 'kind': 'device', 'name': 'User name'},
163+
'org': {'key': 'org-key', 'name': 'Org name'},
164+
}
165+
context = EvaluationContext(None, attributes)
166+
ld_context = context_converter.to_ld_context(context)
167+
168+
assert ld_context.valid is True
169+
assert ld_context.multiple is True
170+
171+
user_context = ld_context.get_individual_context('user')
172+
assert user_context is not None
173+
assert user_context.key == 'user-key'
174+
assert user_context.kind == 'user'
175+
assert user_context.name == 'User name'
176+
177+
org_context = ld_context.get_individual_context('org')
178+
assert org_context is not None
179+
assert org_context.key == 'org-key'
180+
assert org_context.kind == 'org'
181+
assert org_context.name == 'Org name'
182+
183+
159184
def test_multi_context_discards_invalid_single_kind(context_converter: EvaluationContextConverter):
160185
attributes = {
161186
'kind': 'multi',

0 commit comments

Comments
 (0)