Fix New (NB 4.0) Script code with data-sources #9359

Closed
opened 2025-12-29 20:48:58 +01:00 by adam · 1 comment
Owner

Originally created by @arthanson on GitHub (Mar 14, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

NetBox Cloud

NetBox Version

v4.0.0

Python Version

3.8

Steps to Reproduce

There are a couple issues with loading scripts from a data source from the DB representation of Scripts which also fix this issue:

  • setting up a local data-source and creating a Script module from it errored as the script objects were getting instantiated within the sync_data. This was a problem as it was called before the save on ScriptModule so there was no PK for the M2M to save.
  • module_scripts was also getting called before the M2M was setup so there is now a check for this to return an empty dict.
  • module_scripts was cached which is done only on creation so a sync of the data source would not change the internal classes. module_scripts now just needs to be called when the ScriptModule potentially changes so the cache can be removed. This is porting the change from #15439 from reports to the new script code.

Expected Behavior

Scrips should work when loaded from data-sources.

Observed Behavior

An error occurs when adding a script from a data-source.

Originally created by @arthanson on GitHub (Mar 14, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type NetBox Cloud ### NetBox Version v4.0.0 ### Python Version 3.8 ### Steps to Reproduce There are a couple issues with loading scripts from a data source from the DB representation of Scripts which also fix this issue: * setting up a local data-source and creating a Script module from it errored as the script objects were getting instantiated within the sync_data. This was a problem as it was called before the save on ScriptModule so there was no PK for the M2M to save. * module_scripts was also getting called before the M2M was setup so there is now a check for this to return an empty dict. * module_scripts was cached which is done only on creation so a sync of the data source would not change the internal classes. module_scripts now just needs to be called when the ScriptModule potentially changes so the cache can be removed. This is porting the change from #15439 from reports to the new script code. ### Expected Behavior Scrips should work when loaded from data-sources. ### Observed Behavior An error occurs when adding a script from a data-source.
adam added the type: bugstatus: acceptedbetaseverity: medium labels 2025-12-29 20:48:58 +01:00
adam closed this issue 2025-12-29 20:48:59 +01:00
Author
Owner

@arthanson commented on GitHub (Apr 8, 2024):

This had a PR merged that fixed for 4.0 beta, not sure why the PR linkage didnt' work but closing

@arthanson commented on GitHub (Apr 8, 2024): This had a PR merged that fixed for 4.0 beta, not sure why the PR linkage didnt' work but closing
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9359