-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fixes #14829 Simple condition (without and/or) does not work in event rule #14870
base: develop
Are you sure you want to change the base?
Conversation
…ical operator. Added some tests.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
@Julio-Oliveira-Encora would you mind tackling the merge conflicts here? It should just be changes from enabling translation of the error messages. |
Done! |
@arthanson you're free to review this & merge as you see fit. |
ConditionSet(rule) if is_ruleset(rule) else Condition(**rule) | ||
for rule in ruleset[self.logic] | ||
] | ||
if len(ruleset) == 1: |
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.
Is this the correct order below - it seems like they are reversed, the and-or processing is being done if the len(ruleset) == 1 which seems like it should be in the else clause?
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.
It's in the correct order because of the ruleset below, for example, has length = 1 and this case is deal inside the if. All other conditions must be deal in the else. Does it make sense?
{
"or": [
{
"and": [
{
"attr": "status.value",
"value": "active"
},
{
"attr": "primary_ip4",
"negate": true,
"value": null
}
]
},
{
"attr": "tags.slug",
"op": "contains",
"value": "exempt"
}
]
}
…s_not_work_in_event_rule
self.logic = (list(ruleset.keys())[0]).lower() | ||
if self.logic not in (AND, OR): | ||
raise ValueError(_( | ||
f"Invalid logic type: {self.logic} (must be 'AND' or 'OR'). Please check documentation.")) |
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.
remove the f-string here, f strings can't be internationalized
Fixes: #14829
This change allows the addition of simple conditions in the Event Rule. Currently, it only allows to add conditions with logical operators.