diff --git a/CHANGELOG.md b/CHANGELOG.md index dea730406..298e9dfef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,9 @@ * fix `confluent_kafka.store_offsets` if `last_valid_record` is `None`, can happen if a rebalancing happens before the first message was pulled. -- fix pseudonymizer cache metrics not updated +* fix pseudonymizer cache metrics not updated +* fix `_get_value` in `FilterExpression` so that keys don't match on values +* fix `auto_rule_tester` to work with `LOGPREP_BYPASS_RULE_TREE` enabled ## 14.0.0 ### Breaking diff --git a/logprep/filter/expression/filter_expression.py b/logprep/filter/expression/filter_expression.py index 701d2f657..31153ab99 100644 --- a/logprep/filter/expression/filter_expression.py +++ b/logprep/filter/expression/filter_expression.py @@ -85,6 +85,8 @@ def _get_value(key: List[str], document: dict) -> Any: current = document for item in key: + if not isinstance(current, dict): + raise KeyDoesNotExistError if item not in current: raise KeyDoesNotExistError current = current[item] diff --git a/logprep/util/auto_rule_tester/auto_rule_tester.py b/logprep/util/auto_rule_tester/auto_rule_tester.py index 2083a4d5a..01ab7c71a 100644 --- a/logprep/util/auto_rule_tester/auto_rule_tester.py +++ b/logprep/util/auto_rule_tester/auto_rule_tester.py @@ -403,6 +403,8 @@ def _load_rules(self, processor: "Processor", rule_type: str): processor.load_rules(self._empty_rules_dirs, []) elif rule_type == "generic_rules": processor.load_rules([], self._empty_rules_dirs) + if processor._bypass_rule_tree: + processor._rules = processor.rules processor.setup() def _prepare_test_eval( diff --git a/tests/unit/filter/test_filter_expression.py b/tests/unit/filter/test_filter_expression.py index 05f9586ea..bfd770b22 100644 --- a/tests/unit/filter/test_filter_expression.py +++ b/tests/unit/filter/test_filter_expression.py @@ -36,6 +36,11 @@ def test_get_value_fails_empty_key(self): with pytest.raises(KeyDoesNotExistError): FilterExpression._get_value([], {"some": "value"}) + def test_get_value_fails_when_key_matches_value_instead_of_key(self): + document = {"key": "not_a_key"} + with pytest.raises(KeyDoesNotExistError): + FilterExpression._get_value(["key", "not_a_key"], document) + def test_get_value_returns_expected_value(self): document = {"one": {"two": "value"}, "ten": {"eleven": "another value"}}