Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter matching with bypass tree #719

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading