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

Changing event rule action type messes up Conditions field #14838

Closed
markkuleinio opened this issue Jan 18, 2024 · 2 comments · Fixed by #14901
Closed

Changing event rule action type messes up Conditions field #14838

markkuleinio opened this issue Jan 18, 2024 · 2 comments · Fixed by #14901
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@markkuleinio
Copy link
Contributor

markkuleinio commented Jan 18, 2024

Deployment Type

Self-hosted

NetBox Version

v3.7.1

Python Version

3.11

Steps to Reproduce

  1. Go to Operations - Event Rules - Add
  2. Set Conditions = { "and": [{"attr": "status.value", "value": "deprecated"}]}
  3. Select Action type = Script

Expected Behavior

Conditions field stays as-is

Observed Behavior

Conditions field is rewritten as invalid JSON:

"{ \"and\": [{\"attr\": \"status.value\", \"value\": \"deprecated\"}]}"

The quoting is added with every change of the Action type.

This also happens if editing an existing event rule and changing the Action type.

Workaround

  • Copy the Conditions field somewhere
  • Change the Action type
  • Paste the Conditions field back
@markkuleinio markkuleinio added the type: bug A confirmed report of unexpected behavior in the application label Jan 18, 2024
@markkuleinio
Copy link
Contributor Author

markkuleinio commented Jan 18, 2024

Btw, the error message (that happens if the event rule with the modified Conditions is saved) is slightly incorrect:

Ruleset must be a dictionary, not <class 'django.forms.fields.JSONString'>.
Enter conditions in JSON format.

A Python dictionary is not necessarily valid JSON (take for example None vs. null, or single-quotes vs. double-quotes)

@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows labels Jan 18, 2024
@DanSheps DanSheps added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jan 19, 2024
@DanSheps DanSheps self-assigned this Jan 19, 2024
@jeremystretch
Copy link
Member

This is occurring because the initial data passed as a query parameter when re-rendering the form is interpreted as a string and automatically escaped. The same behavior can be observed by manually passing initial data to the form. For instance, GET /extras/event-rules/add/?conditions={"foo": 123} populates the value "{\"foo\": 123}" (a string) into the conditions field.

We need some logic in place to detect and load initial data as JSON, rather than treating it as a string. @DanSheps I'm going to take this one if you don't mind as I think we can fix this pretty easily under the field class' prepare_value() method.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants