Skip to content

Commit 4cb349d

Browse files
committed
fix(flags): fallback when group properties are missing
1 parent 9ec21de commit 4cb349d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎posthog/client.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,11 @@ def _compute_flag_locally(
14601460
)
14611461
return False
14621462

1463-
focused_group_properties = group_properties.get(group_name, {})
1463+
if group_name not in group_properties:
1464+
raise InconclusiveMatchError(
1465+
f"Flag has no group properties for group '{group_name}'"
1466+
)
1467+
focused_group_properties = group_properties[group_name]
14641468
group_key = groups[group_name]
14651469
return match_feature_flag_properties(
14661470
feature_flag,

‎posthog/test/test_feature_flags.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ def test_flag_group_properties(self, patch_get, patch_flags):
233233

234234
self.assertEqual(patch_flags.call_count, 1)
235235

236+
def test_group_flag_is_inconclusive_when_group_properties_missing(self):
237+
feature_flag = {
238+
"id": 1,
239+
"name": "Group Flag Without Property Filters",
240+
"key": "group-flag-no-props",
241+
"active": True,
242+
"filters": {
243+
"aggregation_group_type_index": 0,
244+
"groups": [{"properties": [], "rollout_percentage": 100}],
245+
},
246+
}
247+
self.client.group_type_mapping = {"0": "company"}
248+
249+
with self.assertRaises(InconclusiveMatchError):
250+
self.client._compute_flag_locally(
251+
feature_flag,
252+
"some-distinct-id",
253+
groups={"company": "acme"},
254+
group_properties={},
255+
)
256+
236257
@mock.patch("posthog.client.flags")
237258
@mock.patch("posthog.client.get")
238259
def test_flag_with_complex_definition(self, patch_get, patch_flags):

0 commit comments

Comments
 (0)