Skip to content

Commit f2363e3

Browse files
feat: apply rules based on the all-any type (#313)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Zaimwa9 <wadii.zaim@flagsmith.com>
1 parent fae5c73 commit f2363e3

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "tests/engine_tests/engine-test-data"]
22
path = tests/engine_tests/engine-test-data
33
url = https://github.com/flagsmith/engine-test-data.git
4-
branch = v3.6.0
4+
branch = v3.7.0

flag_engine/segments/evaluator.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,27 +236,30 @@ def context_matches_rule(
236236
) -> bool:
237237
matches_conditions = (
238238
get_matching_function(rule["type"])(
239-
[
240-
context_matches_condition(
241-
context=context,
242-
condition=condition,
243-
segment_key=segment_key,
244-
)
245-
for condition in conditions
246-
]
239+
context_matches_condition(
240+
context=context,
241+
condition=condition,
242+
segment_key=segment_key,
243+
)
244+
for condition in conditions
247245
)
248246
if (conditions := rule.get("conditions"))
249247
else True
250248
)
251249

252-
return matches_conditions and all(
253-
context_matches_rule(
254-
context=context,
255-
rule=rule,
256-
segment_key=segment_key,
250+
matches_rules = (
251+
get_matching_function(rule["type"])(
252+
context_matches_rule(
253+
context=context,
254+
rule=sub_rule,
255+
segment_key=segment_key,
256+
)
257+
for sub_rule in rules
257258
)
258-
for rule in rule.get("rules") or []
259+
if (rules := rule.get("rules"))
260+
else True
259261
)
262+
return matches_conditions and matches_rules
260263

261264

262265
def context_matches_condition(

tests/unit/segments/fixtures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
],
111111
}
112112

113+
113114
segment_conditions_and_nested_rules: SegmentContext = {
114115
"key": "6",
115116
"name": "segment_multiple_conditions_all_and_nested_rules",

0 commit comments

Comments
 (0)