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 negated filters logic: non-boolean AND/OR #247

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

psrok1
Copy link
Member

@psrok1 psrok1 commented Mar 5, 2024

Long story short

Original filter logic was simple:

  • task headers match consumer filter if they match all values defined in filter (AND logic of matches for each key defined in filter)
  • task headers must match any of consumer filters (OR logic for list of filters)

But then we started supporting negated filters (#179) and simply defined negative match as no match. It doesn't work because (as @Antelox found) !linux OR !windows matches windows making that filter a no-op.

Negated filters logic was then fixed by #223, but @ups1decyber found corner cases where proposed algorithm doesn't work as expected (#246)

What was changed?

After analyzing the case, I found that we still want to follow AND/OR logic but we need special value for negative match.

[{"type": "sample", "platform": "win32"}, {"type": "different", "platform": "!win32"}

means: "type MUST BE sample AND platform MUST BE win32" OR "type MUST BE different AND platform CAN'T BE win32"

so !linux OR !windows indeed matches windows but it's special case of match: negative match. Mismatched values (0) should still follow AND/OR logic, but matches should have sign that determines if it's positive match or negative match (1 or -1). Negative match overrides the positive one, because positive match is also lack of filter for specific header value.

Finally non-boolean logic is converted to the boolean value: False for mismatch (0) and negative match (-1), True for positive match (1).

In addition, I added test cases that should cover specific corner cases including these found by @ups1decyber

@ups1decyber
Copy link

Hi @psrok1, thank you for looking into the issue! To me it looks like the bug is fixed!

@psrok1 psrok1 requested a review from msm-cert March 6, 2024 16:58
@nazywam
Copy link
Member

nazywam commented Mar 7, 2024

@msm-cert was more invloved in the discussion so I'll leave the review up to him but I'm thinking if the filter matching is that nontrivial we should probably include a paragraph or two in the documentation about it?

Copy link
Member

@msm-cert msm-cert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and it seems to work as expected for all usecases I've tried.

@psrok1 psrok1 merged commit 81d0bb9 into master Mar 12, 2024
6 checks passed
@psrok1 psrok1 deleted the fix/negated-filters-logic branch March 12, 2024 11:00
@psrok1 psrok1 mentioned this pull request Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Matching a negated filter value makes Task.matches_filters fail regardless of other filters
4 participants