Stale reports remain in Netbox after modifying the Python code #9089

Closed
opened 2025-12-29 20:45:19 +01:00 by adam · 4 comments
Owner

Originally created by @llamafilm on GitHub (Jan 16, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v3.7.0

Python Version

3.10

Steps to Reproduce

  1. Create a local data source with URL like file:///etc/netbox/config/reports
  2. Create a file there with contents from this example: https://github.com/netbox-community/customizations/blob/master/reports/ipam-reports/ip-duplicate.py
  3. Add a new report module from this file via the local data source
  4. Delete the report module
  5. Modify the Python code to remove the UniquePrefixReport class
  6. Resync the data source
  7. Add a new report module from the same Python file

Expected Behavior

It should show only one report for UniqueIPReport

Observed Behavior

It still shows both reports.
image

Trying to view the source results in an error. /extras/reports/ip_duplicate/UniquePrefixReport/source/
image

Originally created by @llamafilm on GitHub (Jan 16, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v3.7.0 ### Python Version 3.10 ### Steps to Reproduce 1. Create a local data source with URL like `file:///etc/netbox/config/reports` 2. Create a file there with contents from this example: https://github.com/netbox-community/customizations/blob/master/reports/ipam-reports/ip-duplicate.py 3. Add a new report module from this file via the local data source 4. Delete the report module 5. Modify the Python code to remove the `UniquePrefixReport` class 6. Resync the data source 7. Add a new report module from the same Python file ### Expected Behavior It should show only one report for `UniqueIPReport` ### Observed Behavior It still shows both reports. <img width="1223" alt="image" src="https://github.com/netbox-community/netbox/assets/3991046/13e4beac-cd44-497f-8f8a-4ab4dfd07dc9"> Trying to view the source results in an error. `/extras/reports/ip_duplicate/UniquePrefixReport/source/` <img width="738" alt="image" src="https://github.com/netbox-community/netbox/assets/3991046/3cbb1273-74bd-4ee9-963e-8de774eba07a">
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:45:19 +01:00
adam closed this issue 2025-12-29 20:45:19 +01:00
Author
Owner

@markkuleinio commented on GitHub (Jan 18, 2024):

The same happens with scripts: if the class name is changed, then there are two scripts listed, but only the "current one" works.

Just to be sure, on 3.7.1 as well:

  1. Create data source:
  • Name = Local scripts
  • Type = Local
  • URL = file:///opt/netbox/netbox/scripts/
  1. Sync the data source
  2. Create this script file "Tunnel.py" in the scripts directory (with owner netbox:netbox):
from extras.scripts import Script

class NewTunnelScript(Script):

    class Meta:
        name = "New VPN tunnel"

    def run(self, data, commit):
        self.log_success("OK")
  1. Go to Customization - Scripts - Add:
  • Data source = Local scripts
  • File = Tunnel.py
  • select Auto sync enabled
  • Create
  1. See that there is script "Tunnel", with name "New VPN tunnel" in it, linking to [...]/NewTunnelScript/
  2. Edit the script file (in the filesystem): change class NewTunnelScript to NewTunnel
  3. Refresh the Scripts page
  4. See that now you have two "New VPN tunnel" names in the list, one links to /NewTunnel/ (correct), another links to /NewTunnelScript/ (does not exist anymore)
  5. Click Delete
  6. Recreate the same script: use steps 3 and 4 above BUT use the class name NewTunnel this time right from the start
  7. See that there are still two names called "New VPN tunnel", one links to /NewTunnel/ (correct), another links to /NewTunnelScript/ (does not exist anywhere)

--> Looks like the script classes are saved to some other memory as well, not just in the script files.

@markkuleinio commented on GitHub (Jan 18, 2024): The same happens with **scripts**: if the class name is changed, then there are two scripts listed, but only the "current one" works. Just to be sure, on 3.7.1 as well: 1. Create data source: - Name = Local scripts - Type = Local - URL = file:///opt/netbox/netbox/scripts/ 2. Sync the data source 3. Create this script file "Tunnel.py" in the scripts directory (with owner netbox:netbox): ``` from extras.scripts import Script class NewTunnelScript(Script): class Meta: name = "New VPN tunnel" def run(self, data, commit): self.log_success("OK") ``` 4. Go to Customization - Scripts - Add: - Data source = Local scripts - File = Tunnel.py - select Auto sync enabled - Create 5. See that there is script "Tunnel", with name "New VPN tunnel" in it, linking to `[...]/NewTunnelScript/` 6. Edit the script file (in the filesystem): change class `NewTunnelScript` to `NewTunnel` 7. Refresh the Scripts page 8. See that now you have **two** "New VPN tunnel" names in the list, one links to `/NewTunnel/` (correct), another links to `/NewTunnelScript/` (does not exist anymore) 9. Click **Delete** 10. Recreate the same script: use steps 3 and 4 above **BUT** use the class name `NewTunnel` this time right from the start 11. See that there are still two names called "New VPN tunnel", one links to `/NewTunnel/` (correct), another links to `/NewTunnelScript/` (does not exist anywhere) --> Looks like the script classes are saved to some other memory as well, not just in the script files.
Author
Owner

@markkuleinio commented on GitHub (Jan 18, 2024):

Apparently restarting NetBox services after deleting the script helps: then only the correct class is shown in the list when the script is added again.

@markkuleinio commented on GitHub (Jan 18, 2024): Apparently restarting NetBox services after deleting the script helps: then only the correct class is shown in the list when the script is added again.
Author
Owner

@kkthxbye-code commented on GitHub (Jan 18, 2024):

@markkuleinio - This was one of the silent removals in 3.5 with the new script system. Pre-3.5 there was code present to ensure that the sys.modules cache was cleared on script load, however this code was removed. So I assume it's intentional not supporting reloading scripts without restarting netbox anymore.

72767fb5b7/netbox/extras/scripts.py (L545-L554)

@kkthxbye-code commented on GitHub (Jan 18, 2024): @markkuleinio - This was one of the silent removals in 3.5 with the new script system. Pre-3.5 there was code present to ensure that the sys.modules cache was cleared on script load, however this code was removed. So I assume it's intentional not supporting reloading scripts without restarting netbox anymore. https://github.com/netbox-community/netbox/blob/72767fb5b78e59cac50b73a49937b38a4a80c0eb/netbox/extras/scripts.py#L545-L554
Author
Owner

@jeremystretch commented on GitHub (Jan 23, 2024):

So I assume it's intentional not supporting reloading scripts without restarting netbox anymore.

No, this is not intentional, and you can very easily see that uploading new reports/scripts works without needing to restart any services. @kkthxbye-code since you've already tracked this down perhaps you'd like to put in a PR?

@jeremystretch commented on GitHub (Jan 23, 2024): > So I assume it's intentional not supporting reloading scripts without restarting netbox anymore. No, this is not intentional, and you can very easily see that uploading new reports/scripts works without needing to restart any services. @kkthxbye-code since you've already tracked this down perhaps you'd like to put in a PR?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9089