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: EventBus: Exists prefix not considered for rule matching #9931
Fix: EventBus: Exists prefix not considered for rule matching #9931
Conversation
LocalStack Community integration with Pro 2 files 2 suites 1h 12m 42s ⏱️ Results for commit e3283a4. ♻️ This comment has been updated with latest results. |
3a69385
to
11dafcc
Compare
11dafcc
to
0f1b97d
Compare
If the pattern is set to [("exists": False)] the getter for the key in the rule will always revert to the fallback object, but the message should still be sent
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.
PR is already in a good state to merge, but I have a few suggestions. They can be either tackled in this PR, later or just added as TODOs for future us 👍
Sorry you had to deal with such an annoying test as one of your first bigger AWS tests 😅 Glad we could find a reliable solution in the end.
messages = put_events_with_filter_to_sqs( | ||
pattern=test_event_pattern_exists, | ||
entries_asserts=entries_asserts, | ||
) | ||
snapshot.match("rule-exists-true", messages) | ||
|
||
messages_not_exists = put_events_with_filter_to_sqs( | ||
pattern=test_event_pattern_not_exists, | ||
entries_asserts=entries_asserts_exists_false, | ||
) | ||
snapshot.match("rule-exists-false", messages_not_exists) |
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.
From the docs: Exists matching only works on leaf nodes. It does not work on intermediate nodes.
Might be something that needs to be covered via a negative test as well at some point
if element_value and event_value: | ||
return True |
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.
Not sure if AWS behaves the same here with checking truthiness vs. just "not being None". Can be tackled in the future though
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.
E.g.
{
"detail": {
"state": [ { "exists": true } ]
}
}
with
{
...
"detail": {
"state": 0
}
}
I'd assume this should still select but we'd need to this this 🤷♂️
Split exists True and exists False into two separate tests for improved readability.
Motivation
As reported in #8512 and #7305 the current behavior does not fully match the aws cli behavior regarding the EventBridge pattern
{"exists": True}
.This rule:
in combination with this message:
does not match on LocalStack, but does correctly match on AWS.
The issue arises from the prefix
exists
not being considered.Furthermore, the opposite pattern
[("exists"): False]
was also not correctly matchedThis rule:
in combination with this message:
Changes
Adding a condition to check for the prefix
exists
and use the boolean value in combination with the condition if there value to return exists for the pattern[("exists"): True]
.The pattern
[("exists"): False]
needs different handling, since per definition, the getter of the message event for the in the pattern defined key will always fail to the fallback object. To still send the message correctly, an additional check is put in place handling this particular instance when the return value is not presented, that is onlyTrue
in the condition that the pattern prefix equal"exists"
see (provider.py
line 516).Fixes #8512 and fixes #7305
Testing
Polling for sqs messages was changed to long poll due to inconsistencies when generating the snapshots against aws with messages not being received.