diff --git a/flag_engine/segments/evaluator.py b/flag_engine/segments/evaluator.py index 0b8f8fc..65a380b 100644 --- a/flag_engine/segments/evaluator.py +++ b/flag_engine/segments/evaluator.py @@ -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( diff --git a/tests/engine_tests/engine-test-data b/tests/engine_tests/engine-test-data index 9307930..6c381cc 160000 --- a/tests/engine_tests/engine-test-data +++ b/tests/engine_tests/engine-test-data @@ -1 +1 @@ -Subproject commit 9307930e9e64482a35e7d6b254225addb6e44687 +Subproject commit 6c381ccadf6da73dedf6aff35e96d24546359a1e diff --git a/tests/unit/segments/fixtures.py b/tests/unit/segments/fixtures.py index 934311c..5ea6698 100644 --- a/tests/unit/segments/fixtures.py +++ b/tests/unit/segments/fixtures.py @@ -110,6 +110,7 @@ ], } + segment_conditions_and_nested_rules: SegmentContext = { "key": "6", "name": "segment_multiple_conditions_all_and_nested_rules",