-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Events: fix anything-but with null values #13268
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
Conversation
Test Results - Alternative Providers406 tests 274 ✅ 4m 8s ⏱️ Results for commit d7e2d4b. ♻️ This comment has been updated with latest results. |
LocalStack Community integration with Pro 2 files ± 0 2 suites ±0 58m 15s ⏱️ - 1h 1m 11s Results for commit d7e2d4b. ± Comparison against base commit 73e4f6c. This pull request removes 2163 and adds 27 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Test Results (amd64) - Integration, Bootstrap 5 files 5 suites 1h 24m 14s ⏱️ Results for commit d7e2d4b. ♻️ This comment has been updated with latest results. |
maxhoheiser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greate changes, I noticed a few small gaps and nits, but after these are addressed good to merge.
Good catch that we need the null checks in the _evaluate... methods.
Quite a lot of tests to cover this 👍
Nit:
if (suffix_equal_ignore_case := suffix.get("equals-ignore-case")) is not None: should we use the walrus operator more frequently?
localstack-core/localstack/services/events/event_rule_engine.py
Outdated
Show resolved
Hide resolved
localstack-core/localstack/services/events/event_rule_engine.py
Outdated
Show resolved
Hide resolved
localstack-core/localstack/services/events/event_rule_engine.py
Outdated
Show resolved
Hide resolved
localstack-core/localstack/services/events/event_rule_engine.py
Outdated
Show resolved
Hide resolved
| # anything-but can actually contain any kind of simple rule (str, number, and list) except Null | ||
| if value is None: | ||
| raise InvalidEventPatternException( | ||
| f"{self.error_prefix}Value of anything-but must be an array or single string/number value." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| f"{self.error_prefix}Value of anything-but must be an array or single string/number value." | |
| f"{self.error_prefix}"Value of anything-but cannot be null. Expected array or string/number value." |
nit - this might be clearer that null is absolutely not allowed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a parity error returned by AWS, and while I agree with the comment, can't do anything about it 😄
| self._validate_rule(v) | ||
| if v is None: | ||
| raise InvalidEventPatternException( | ||
| f"{self.error_prefix}Inside anything but list, start|null|boolean is not supported." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be string? or what is start :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above, AWS returns this error, I also don't know what start means 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the review! Also added the missing type hints in the _evaluate_* methods that you spotted, good catch! I've changed them to t.Any to take into the account they could be also something else than None and properly handle those cases to be strictly strings, we're now properly covered I believe.
Edit: regarding the walrus operator, I tend to use it quite frequently, it especially helps here 👍
| # anything-but can actually contain any kind of simple rule (str, number, and list) except Null | ||
| if value is None: | ||
| raise InvalidEventPatternException( | ||
| f"{self.error_prefix}Value of anything-but must be an array or single string/number value." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a parity error returned by AWS, and while I agree with the comment, can't do anything about it 😄
| self._validate_rule(v) | ||
| if v is None: | ||
| raise InvalidEventPatternException( | ||
| f"{self.error_prefix}Inside anything but list, start|null|boolean is not supported." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above, AWS returns this error, I also don't know what start means 🤷♂️
Motivation
We got a report from a user that when using
anything-butwith nestedsuffix, and the target field was missing from the event, we would raise an internal error as we were not handlingnullvalue accordingly.We need to differentiate between 2 kind of
nullvalue: missing value (result ofevent.get()) and user-setnull.If the user is setting the value to
null, the default behavior ofanything-butworks, meaning that it returns true like any string not matching the pattern would.If the value is missing entirely, then we're not in the "anything but" case, and it returns
False.Changes
nullvalue in the pattern foranything-butpatternsanything-butand its nested conditions with both missing values and user-setnullvaluesnullvalues, and handle them depending on their existence or not