Cascades event rule when the associated script is deleted
Fixes: #14852
I have added the events_rules like suggested but there is an issue that I'm facing with the code. The handle_deleted_object signal gets called when I try to delete the script and the code fails with the following error
File "/home/asaharan/PycharmProjects/netbox/netbox/extras/api/serializers.py", line 90, in get_action_object
script = instance.action_object.scripts[script_name]()
KeyError: 'AddDeviceTypeComponents'
I checked the that instance.action_object points to the ScriptModule but calling scripts just returns an empty dictionary which is the reason for the KeyError. How do you want me to handle this? This issue was not with the delete overide I did though
@abhi1693 I haven't dug too deeply into this bug, but normally scripts should have the script_name in it, however if this is from the delete case I can think of two potential solutions:
- in the serializer check if script_name is in scripts and if not return a null object for the nested serializer.
- I think you said this comes from the call to handle_deleted_object? If that is the case then possibly not do the serializer call if there are no script objects? (not sure on this one).
If you could message me the repro and the line of code in the handle_deleted_object where this is getting called it would help to get context. I think the main issue is why is scripts returning none if the action_parameter is set, which shouldn't really be happening. If the scripts is returning none from deletion. then the action_parameter should be empty as well. The action_parameter is the name of the actual method to call as the action_object just points to the script model and not the actual method to call. I hope that helps.
@arthanson The repro steps are simple:
- Add the code Jeremy has suggested
- Upload a script. I chose add_device_type_components
- Create an event rule with this script (choose whatever required options)
- Then try deleting the script. You will get a nice widget showing the event and the relationship will be deleted, proceed further and you will get hit with the issue
closing as addressed in #15888