-
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
Enable Event Rules to process and send data to Scripts using Event Data #15063
base: develop
Are you sure you want to change the base?
Enable Event Rules to process and send data to Scripts using Event Data #15063
Conversation
…process the input data inside the script form
Neither of these FRs have been approved before submitting this PR, and even if they had been, they would each need a separate PR. I understand that it's tempting to save time by combining work, but that also makes effective review and documentation very difficult. I've just marked #14884 as approved and assigned it to you, but please revise the PR to remove the introduction of additional context so that we can focus on its specific goal. |
@jeremystretch, updated the PR, and the changes in the code reflects only the task of passing action_data to the script just like the other methods, i.e the script develop may access the input the same way he access the forms. |
@renatoalmeidaoliveira did you push your changes? I don't see any updates. |
@jeremystretch I may have missundertud what you asked. The changes I've made was: You mean to just pass |
I can put all code inside process_event_rules too, |
…on data to Script
@jeremystretch updated the code to restrict the changes only to process_event_rule inside the Script context. |
Is there a reason why this implementation only affect EventRuleActionChoices.SCRIPT? My use-case is to be able to use more data in a webhook payload than what I get from the default event rule "data" dict. |
@aharrisson imo the implementation should be the same to both Webhoocks and Scripts, giving the user more flexibility to pass data to his actions. |
@renatoalmeidaoliveira , Thank you for the quick reply. |
Currently, if I have an event rule that triggers when an IP address is created, modified, or deleted — it's impossible for the script to know which action triggered it. Will this PR address that? |
@llamafilm short answer, in the implementation of this PR yes. |
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. |
@renatoalmeidaoliveira after reviewing with Jeremy, the jinja2 processing shouldn't be here, the data should just be passed as a json blob without going through jinja2. Can you please update the PR for this? |
Discussed with @renatoalmeidaoliveira - I need to review the points he brought up, will do later this week. |
'request_id': request_id, | ||
'model': data, | ||
} | ||
rendered_data = render_jinja2(json.dumps(event_rule.action_data), context) |
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.
Sorry, I don't see why the render_jinja2 is needed here - event_rule.action_data should just be the json (dictionary) which should be able to get directly passed to the script. I'm thinking you could just change the Job.enqueue to pass event_rule.action_data as the data param.
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.
@arthanson If we don't render the jinja2 how the user gonna pass variables to the script, for example:
1 - For example the Script form expects an Interface ID, or some model attribute.
If It didn't run the jinja2 how the user gonna be able to pass models variables to be processed by the script form?
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.
The user doens't have the model params when he defines the event rule, so I think there must be some way for him to reference the models and the changelogs, to build the data that gonna be passed to the Script form
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.
The action_data
field on EventRule holds a dictionary of arbitrary additional data. This doesn't require any mutation; it just needs to be passed to the script, and the script needs to accommodate whatever data is being passed as variables.
I think you're trying to accomplish something different than what I agreed to here. There's no reason to manipulate the data before sending it to the script; the script just needs to be written to accept the data as passed.
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.
@jeremystretch even if I pass the event_data
as is to the script how the Script developer gonna be able to reference the event object like the changed object, since it doesn't have that data inside the Script? another thing is that way breaks the common script logic where the developer expects the data dict to return a parsed form
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.
Going further if the action_data is a static value what's the meaning of having it at all, the Script dev could just create the script with that data hard coded
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. |
Fixes: #14884
Passes Event Rule a jinja2 processed
action_data
to script execution as its input.