Skip to content

Commit

Permalink
Fix filter matching with bypass tree (#719)
Browse files Browse the repository at this point in the history
* Make auto rule tester work with bypass rule tree
* Fix FilterExpression to prevent incorrect matching
  • Loading branch information
ppcad authored Dec 5, 2024
1 parent 4219101 commit ac2b2f8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions logprep/filter/expression/filter_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions logprep/util/auto_rule_tester/auto_rule_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/filter/test_filter_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}

Expand Down

0 comments on commit ac2b2f8

Please sign in to comment.