Skip to content

Commit e287565

Browse files
committed
Move accessing variants outside of loop
`flag_variants` doesn't depend on condition so it doesn't make sense to declare it in the loop.
1 parent 0f8b10b commit e287565

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

posthog/feature_flags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def match_feature_flag_properties(flag, distinct_id, properties, cohort_properti
5353
flag_conditions = (flag.get("filters") or {}).get("groups") or []
5454
is_inconclusive = False
5555
cohort_properties = cohort_properties or {}
56+
# Some filters can be explicitly set to null, which require accessing variants like so
57+
flag_variants = ((flag.get("filters") or {}).get("multivariate") or {}).get("variants") or []
5658

5759
# Stable sort conditions with variant overrides to the top. This ensures that if overrides are present, they are
5860
# evaluated first, and the variant override is applied to the first matching condition.
@@ -67,8 +69,6 @@ def match_feature_flag_properties(flag, distinct_id, properties, cohort_properti
6769
# the matching variant
6870
if is_condition_match(flag, distinct_id, condition, properties, cohort_properties):
6971
variant_override = condition.get("variant")
70-
# Some filters can be explicitly set to null, which require accessing variants like so
71-
flag_variants = ((flag.get("filters") or {}).get("multivariate") or {}).get("variants") or []
7272
if variant_override and variant_override in [variant["key"] for variant in flag_variants]:
7373
variant = variant_override
7474
else:

0 commit comments

Comments
 (0)