From 641750eb1984b3bc3000d279549e701448a404ae Mon Sep 17 00:00:00 2001 From: Ran Isenberg Date: Fri, 1 Oct 2021 21:21:49 +0300 Subject: [PATCH] fix: Feature Flag only evaluates first rule in a feature --- .../utilities/feature_flags/feature_flags.py | 7 +++---- tests/functional/feature_flags/test_feature_flags.py | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/aws_lambda_powertools/utilities/feature_flags/feature_flags.py b/aws_lambda_powertools/utilities/feature_flags/feature_flags.py index a4622fa9272..fda3138ca20 100644 --- a/aws_lambda_powertools/utilities/feature_flags/feature_flags.py +++ b/aws_lambda_powertools/utilities/feature_flags/feature_flags.py @@ -102,10 +102,9 @@ def _evaluate_rules( if self._evaluate_conditions(rule_name=rule_name, feature_name=feature_name, rule=rule, context=context): return bool(rule_match_value) - # no rule matched, return default value of feature - logger.debug(f"no rule matched, returning feature default, default={feat_default}, name={feature_name}") - return feat_default - return False + # no rule matched, return default value of feature + logger.debug(f"no rule matched, returning feature default, default={feat_default}, name={feature_name}") + return feat_default def get_configuration(self) -> Dict: """Get validated feature flag schema from configured store. diff --git a/tests/functional/feature_flags/test_feature_flags.py b/tests/functional/feature_flags/test_feature_flags.py index f6ce93abaa9..73702de93b2 100644 --- a/tests/functional/feature_flags/test_feature_flags.py +++ b/tests/functional/feature_flags/test_feature_flags.py @@ -233,9 +233,9 @@ def test_flags_conditions_no_rule_match_equal_multiple_conditions(mocker, config # check rule match for multiple of action types def test_flags_conditions_rule_match_multiple_actions_multiple_rules_multiple_conditions(mocker, config): expected_value_first_check = True - expected_value_second_check = False + expected_value_second_check = True expected_value_third_check = False - expected_value_fourth_case = False + expected_value_fourth_check = False mocked_app_config_schema = { "my_feature": { "default": expected_value_third_check, @@ -295,9 +295,9 @@ def test_flags_conditions_rule_match_multiple_actions_multiple_rules_multiple_co toggle = feature_flags.evaluate( name="my_fake_feature", context={"tenant_id": "11114446", "username": "ab"}, - default=expected_value_fourth_case, + default=expected_value_fourth_check, ) - assert toggle == expected_value_fourth_case + assert toggle == expected_value_fourth_check # check a case where the feature exists but the rule doesn't match so we revert to the default value of the feature