Skip to content
Open
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
31 changes: 17 additions & 14 deletions flag_engine/segments/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,30 @@ def context_matches_rule(
) -> bool:
matches_conditions = (
get_matching_function(rule["type"])(
[
context_matches_condition(
context=context,
condition=condition,
segment_key=segment_key,
)
for condition in conditions
]
context_matches_condition(
context=context,
condition=condition,
segment_key=segment_key,
)
for condition in conditions
)
if (conditions := rule.get("conditions"))
else True
)

return matches_conditions and all(
context_matches_rule(
context=context,
rule=rule,
segment_key=segment_key,
matches_rules = (
get_matching_function(rule["type"])(
context_matches_rule(
context=context,
rule=sub_rule,
segment_key=segment_key,
)
for sub_rule in rules
)
for rule in rule.get("rules") or []
if (rules := rule.get("rules"))
else True
)
return matches_conditions and matches_rules


def context_matches_condition(
Expand Down
1 change: 1 addition & 0 deletions tests/unit/segments/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
],
}


segment_conditions_and_nested_rules: SegmentContext = {
"key": "6",
"name": "segment_multiple_conditions_all_and_nested_rules",
Expand Down
Loading