Scripts issue post v4.0.2 upgrade #9709

Closed
opened 2025-12-29 21:21:26 +01:00 by adam · 8 comments
Owner

Originally created by @cruse1977 on GitHub (May 21, 2024).

Deployment Type

Self-hosted

NetBox Version

4.0.2

Python Version

3.12

Steps to Reproduce

This bug occurs with a 3.7 -> 4.x upgrade and cannot be resolved without removing affected scripts. It only occurs when the upgrade occurs with missing scripts.

Replicate empty 'file' environment whereas DB has been restored but files NOT:

  • Create Script using git datastore
  • Manually remove file from netbox scripts dir ; breaking things and replicating an unsynced environment

Go to Script:

  • Expected: NetBox 3.7: 'error: missing file'.
  • Observed: Missing file

Run Upgrade to 4.0.2 - upgrade succeeds

Go to scripts -

  • expected: runnable (if data source has synced)
  • Observed: unable to run scripts, run button missing, clicking edit yields to empty form

Sync datasource (UI, or manage.py syncdatasource --all) manually

  • Expected: script recreated, script can run
  • Observed: no change in behaviour as above - also no files created in scripts/ directory

REPO used: https://github.com/cruse1977/test-scripts

Expected Behavior

  • Following a git sync scripts should become runnable and exist in the /script directory

Observed Behavior

  • following a git sync (successful), no change in behaviour; no runs button, no files created in /scripts; editting the script gives an empty form with no pre-populated items (ie: the data source). Manually copying the affected script to /scripts also does not resolve this.
Originally created by @cruse1977 on GitHub (May 21, 2024). ### Deployment Type Self-hosted ### NetBox Version 4.0.2 ### Python Version 3.12 ### Steps to Reproduce This bug occurs with a 3.7 -> 4.x upgrade and cannot be resolved without removing affected scripts. It only occurs when the upgrade occurs with missing scripts. Replicate empty 'file' environment whereas DB has been restored but files NOT: - Create Script using git datastore - Manually remove file from netbox scripts dir ; breaking things and replicating an unsynced environment Go to Script: - Expected: NetBox 3.7: 'error: missing file'. - Observed: Missing file Run Upgrade to 4.0.2 - upgrade succeeds Go to scripts - - expected: runnable (if data source has synced) - Observed: unable to run scripts, run button missing, clicking edit yields to empty form Sync datasource (UI, or manage.py syncdatasource --all) manually - Expected: script recreated, script can run - Observed: no change in behaviour as above - also no files created in scripts/ directory REPO used: https://github.com/cruse1977/test-scripts ### Expected Behavior - Following a git sync scripts should become runnable and exist in the /script directory ### Observed Behavior - following a git sync (successful), no change in behaviour; no runs button, no files created in /scripts; editting the script gives an empty form with no pre-populated items (ie: the data source). Manually copying the affected script to /scripts also does not resolve this.
adam added the type: bugseverity: medium labels 2025-12-29 21:21:26 +01:00
adam closed this issue 2025-12-29 21:21:26 +01:00
Author
Owner

@jeffgdotorg commented on GitHub (May 21, 2024):

@cruse1977 thanks for the report and the example script.

@jeffgdotorg commented on GitHub (May 21, 2024): @cruse1977 thanks for the report and the example script.
Author
Owner

@llamafilm commented on GitHub (May 21, 2024):

I ran into this problem because my CD dev pipeline tries to launch a new VM, restore the latest database backup locally, install the new Netbox, then run upgrade.sh. It's a catch-22 because you can't run syncdatasource before the venv is created; And if you create the venv first by running upgrade.sh then 0109_script_model.py does not properly update the scripts.

@llamafilm commented on GitHub (May 21, 2024): I ran into this problem because my CD dev pipeline tries to launch a new VM, restore the latest database backup locally, install the new Netbox, then run `upgrade.sh`. It's a catch-22 because you can't run `syncdatasource` before the venv is created; And if you create the venv first by running `upgrade.sh` then [0109_script_model.py](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/migrations/0109_script_model.py) does not properly update the scripts.
Author
Owner

@cruse1977 commented on GitHub (May 23, 2024):

Did some digging on this - this look in part to be due to somewhere in the migration and creation of the ScriptModule objects; the data source being blanked but this is intermittent:

  • NetBox 3.7 - Create git data source; sync; add script
  • Remove script file from /scripts directory
  • Run Upgrade

Upgrade 1: - migration creating empty data source ID

print(ScriptModule.objects.all()[0].dict)

{'_state': <django.db.models.base.ModelState object at 0xffffa3fc1250>, 'id': 1, 'data_source_id': None, 'data_file_id': None, 'data_path': '', 'auto_sync_enabled': False, 'data_synced': None, 'created': datetime.datetime(2024, 5, 22, 23, 50, 10, 653661, tzinfo=datetime.timezone.utc), 'last_updated': None, 'file_root': 'scripts', 'file_path': 'NewSiteScript.py'}

Upgrade 2: - migration correctly preserving data source id

{'_state': <django.db.models.base.ModelState object at 0xffffb4755510>, 'id': 2, 'data_source_id': 1, 'data_file_id': 1, 'data_path': 'NewSiteScript.py', 'auto_sync_enabled': True, 'data_synced': datetime.datetime(2024, 5, 23, 0, 18, 57, 940416, tzinfo=datetime.timezone.utc), 'created': datetime.datetime(2024, 5, 23, 0, 15, 51, 102798, tzinfo=datetime.timezone.utc), 'last_updated': None, 'file_root': 'scripts', 'file_path': 'NewSiteScript.py'}

When the data source is preserved, running an 'edit' then save, seems to sync the data source, updates the is_executable flag which allows the script to run - but its not available until this is done.

@cruse1977 commented on GitHub (May 23, 2024): Did some digging on this - this look in part to be due to somewhere in the migration and creation of the ScriptModule objects; the data source being blanked but this is intermittent: - NetBox 3.7 - Create git data source; sync; add script - Remove script file from /scripts directory - Run Upgrade Upgrade 1: - migration creating empty data source ID print(ScriptModule.objects.all()[0].__dict__) `{'_state': <django.db.models.base.ModelState object at 0xffffa3fc1250>, 'id': 1, 'data_source_id': None, 'data_file_id': None, 'data_path': '', 'auto_sync_enabled': False, 'data_synced': None, 'created': datetime.datetime(2024, 5, 22, 23, 50, 10, 653661, tzinfo=datetime.timezone.utc), 'last_updated': None, 'file_root': 'scripts', 'file_path': 'NewSiteScript.py'}` Upgrade 2: - migration correctly preserving data source id `{'_state': <django.db.models.base.ModelState object at 0xffffb4755510>, 'id': 2, 'data_source_id': 1, 'data_file_id': 1, 'data_path': 'NewSiteScript.py', 'auto_sync_enabled': True, 'data_synced': datetime.datetime(2024, 5, 23, 0, 18, 57, 940416, tzinfo=datetime.timezone.utc), 'created': datetime.datetime(2024, 5, 23, 0, 15, 51, 102798, tzinfo=datetime.timezone.utc), 'last_updated': None, 'file_root': 'scripts', 'file_path': 'NewSiteScript.py'}` When the data source is preserved, running an 'edit' then save, seems to sync the data source, updates the is_executable flag which allows the script to run - but its not available until this is done.
Author
Owner

@cruse1977 commented on GitHub (May 23, 2024):

I ran into this problem because my CD dev pipeline tries to launch a new VM, restore the latest database backup locally, install the new Netbox, then run upgrade.sh. It's a catch-22 because you can't run syncdatasource before the venv is created; And if you create the venv first by running upgrade.sh then 0109_script_model.py does not properly update the scripts.

I think there's a few things going on here; one is the migration sometimes blanking the data source; the other is when the sync occurs within NetBox. See my other post on this.

@cruse1977 commented on GitHub (May 23, 2024): > I ran into this problem because my CD dev pipeline tries to launch a new VM, restore the latest database backup locally, install the new Netbox, then run `upgrade.sh`. It's a catch-22 because you can't run `syncdatasource` before the venv is created; And if you create the venv first by running `upgrade.sh` then [0109_script_model.py](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/migrations/0109_script_model.py) does not properly update the scripts. I think there's a few things going on here; one is the migration sometimes blanking the data source; the other is when the sync occurs within NetBox. See my other post on this.
Author
Owner

@jeremystretch commented on GitHub (Jun 18, 2024):

Observed: unable to run scripts, run button missing, clicking edit yields to empty form

I don't see this on v4.0.5. What I did:

  1. Install v3.7.8 & populate demo data
  2. Create a remote data source (I used a "local" source vs. git but this should not make a difference)
  3. Create a script module from a file on the remote source
  4. Delete the local script file from disk
  5. Upgrade to v4.0.5.

The script is not listed initially due to the missing file, but after clicking the "edit" button for the script module, I see the edit form as expected:

screenshot

And clicking "save" re-populates the file as expected, and it can then be run successfully. If this was a problem on v4.0.2, it's likely been resolved in a more recent release. @cruse1977 can you please attempt to recreate this behavior when upgrading from v3.7.8 to v4.0.5?

@jeremystretch commented on GitHub (Jun 18, 2024): > Observed: unable to run scripts, run button missing, clicking edit yields to empty form I don't see this on v4.0.5. What I did: 1. Install v3.7.8 & populate demo data 2. Create a remote data source (I used a "local" source vs. git but this should not make a difference) 3. Create a script module from a file on the remote source 4. Delete the _local_ script file from disk 5. Upgrade to v4.0.5. The script is not listed initially due to the missing file, but after clicking the "edit" button for the script module, I see the edit form as expected: ![screenshot](https://github.com/netbox-community/netbox/assets/13487278/ecd1ed2f-e99f-4353-a2f3-ef223380b606) And clicking "save" re-populates the file as expected, and it can then be run successfully. If this was a problem on v4.0.2, it's likely been resolved in a more recent release. @cruse1977 can you please attempt to recreate this behavior when upgrading from v3.7.8 to v4.0.5?
Author
Owner

@github-actions[bot] commented on GitHub (Jun 28, 2024):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Jun 28, 2024): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@llamafilm commented on GitHub (Jun 28, 2024):

After editing as Jeremy described, this is working for me in 4.0.5.

@llamafilm commented on GitHub (Jun 28, 2024): After editing as Jeremy described, this is working for me in 4.0.5.
Author
Owner

@jeffgdotorg commented on GitHub (Jul 9, 2024):

Resolving as @llamafilm reports it's fixed in v4.0.5.

@jeffgdotorg commented on GitHub (Jul 9, 2024): Resolving as @llamafilm reports it's fixed in v4.0.5.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9709