migration failure if old scripts exist in db that no longer exist on disk (0109_script_model) #9616

Closed
opened 2025-12-29 21:19:47 +01:00 by adam · 2 comments
Owner

Originally created by @ITJamie on GitHub (May 8, 2024).

Originally assigned to: @DanSheps on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.0

Python Version

3.11

Steps to Reproduce

not sure on exact steps yet. but scripts need to exist in the db that no longer exist on disk.

Expected Behavior

migration should complete successfully even if there are missing scripts

Observed Behavior

db migration fails and blocks netbox from starting.

netbox-1               | ⚙️ Applying database migrations
netbox-1               | 🧬 loaded config '/etc/netbox/config/configuration.py'
netbox-1               | 🧬 loaded config '/etc/netbox/config/extra.py'
netbox-1               | 🧬 loaded config '/etc/netbox/config/logging.py'
netbox-1               | 🧬 loaded config '/etc/netbox/config/plugins.py'
netbox-1               | Operations to perform:
netbox-1               |   Apply all migrations: account, auth, circuits, contenttypes, core, dcim, django_rq, extras, ipam, netbox_gateways, sessions, social_django, taggit, tenancy, users, virtualization, vpn, wireless
netbox-1               | Running migrations:
netbox-1               | Traceback (most recent call last):
netbox-1               |   File "/opt/netbox/netbox/./manage.py", line 10, in <module>
netbox-1               |     execute_from_command_line(sys.argv)
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
netbox-1               |     utility.execute()
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
netbox-1               |     self.fetch_command(subcommand).run_from_argv(self.argv)
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv
netbox-1               |     self.execute(*args, **cmd_options)
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute
netbox-1               |     output = self.handle(*args, **options)
netbox-1               |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/base.py", line 107, in wrapper
netbox-1               |     res = handle_func(*args, **kwargs)
netbox-1               |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 356, in handle
netbox-1               |     post_migrate_state = executor.migrate(
netbox-1               |                          ^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate
netbox-1               |     state = self._migrate_all_forwards(
netbox-1               |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
netbox-1               |     state = self.apply_migration(
netbox-1               |             ^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
netbox-1               |     state = migration.apply(state, schema_editor)
netbox-1               |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/migration.py", line 132, in apply
netbox-1               |     operation.database_forwards(
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
netbox-1               |     self.code(from_state.apps, schema_editor)
netbox-1               |   File "/opt/netbox/netbox/extras/migrations/0109_script_model.py", line 93, in update_scripts
netbox-1               |     for script_name in get_module_scripts(module):
netbox-1               |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/extras/migrations/0109_script_model.py", line 63, in get_module_scripts
netbox-1               |     module = loader.load_module()
netbox-1               |              ^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "<frozen importlib._bootstrap_external>", line 605, in _check_name_wrapper
netbox-1               |   File "<frozen importlib._bootstrap_external>", line 1120, in load_module
netbox-1               |   File "<frozen importlib._bootstrap_external>", line 945, in load_module
netbox-1               |   File "<frozen importlib._bootstrap>", line 290, in _load_module_shim
netbox-1               |   File "<frozen importlib._bootstrap>", line 721, in _load
netbox-1               |   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
netbox-1               |   File "<frozen importlib._bootstrap_external>", line 936, in exec_module
netbox-1               |   File "<frozen importlib._bootstrap_external>", line 1073, in get_code
netbox-1               |   File "<frozen importlib._bootstrap_external>", line 1130, in get_data
netbox-1               | FileNotFoundError: [Errno 2] No such file or directory: '/opt/netbox/netbox/scripts/add_gateways_to_prefixes.py'
Originally created by @ITJamie on GitHub (May 8, 2024). Originally assigned to: @DanSheps on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.0 ### Python Version 3.11 ### Steps to Reproduce not sure on exact steps yet. but scripts need to exist in the db that no longer exist on disk. ### Expected Behavior migration should complete successfully even if there are missing scripts ### Observed Behavior db migration fails and blocks netbox from starting. ``` netbox-1 | ⚙️ Applying database migrations netbox-1 | 🧬 loaded config '/etc/netbox/config/configuration.py' netbox-1 | 🧬 loaded config '/etc/netbox/config/extra.py' netbox-1 | 🧬 loaded config '/etc/netbox/config/logging.py' netbox-1 | 🧬 loaded config '/etc/netbox/config/plugins.py' netbox-1 | Operations to perform: netbox-1 | Apply all migrations: account, auth, circuits, contenttypes, core, dcim, django_rq, extras, ipam, netbox_gateways, sessions, social_django, taggit, tenancy, users, virtualization, vpn, wireless netbox-1 | Running migrations: netbox-1 | Traceback (most recent call last): netbox-1 | File "/opt/netbox/netbox/./manage.py", line 10, in <module> netbox-1 | execute_from_command_line(sys.argv) netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line netbox-1 | utility.execute() netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute netbox-1 | self.fetch_command(subcommand).run_from_argv(self.argv) netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv netbox-1 | self.execute(*args, **cmd_options) netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute netbox-1 | output = self.handle(*args, **options) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/base.py", line 107, in wrapper netbox-1 | res = handle_func(*args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 356, in handle netbox-1 | post_migrate_state = executor.migrate( netbox-1 | ^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate netbox-1 | state = self._migrate_all_forwards( netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards netbox-1 | state = self.apply_migration( netbox-1 | ^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration netbox-1 | state = migration.apply(state, schema_editor) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/migration.py", line 132, in apply netbox-1 | operation.database_forwards( netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards netbox-1 | self.code(from_state.apps, schema_editor) netbox-1 | File "/opt/netbox/netbox/extras/migrations/0109_script_model.py", line 93, in update_scripts netbox-1 | for script_name in get_module_scripts(module): netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/extras/migrations/0109_script_model.py", line 63, in get_module_scripts netbox-1 | module = loader.load_module() netbox-1 | ^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "<frozen importlib._bootstrap_external>", line 605, in _check_name_wrapper netbox-1 | File "<frozen importlib._bootstrap_external>", line 1120, in load_module netbox-1 | File "<frozen importlib._bootstrap_external>", line 945, in load_module netbox-1 | File "<frozen importlib._bootstrap>", line 290, in _load_module_shim netbox-1 | File "<frozen importlib._bootstrap>", line 721, in _load netbox-1 | File "<frozen importlib._bootstrap>", line 690, in _load_unlocked netbox-1 | File "<frozen importlib._bootstrap_external>", line 936, in exec_module netbox-1 | File "<frozen importlib._bootstrap_external>", line 1073, in get_code netbox-1 | File "<frozen importlib._bootstrap_external>", line 1130, in get_data netbox-1 | FileNotFoundError: [Errno 2] No such file or directory: '/opt/netbox/netbox/scripts/add_gateways_to_prefixes.py' ```
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:19:47 +01:00
adam closed this issue 2025-12-29 21:19:47 +01:00
Author
Owner

@ITJamie commented on GitHub (May 8, 2024):

slack convo

@ITJamie commented on GitHub (May 8, 2024): [slack convo](https://netdev-community.slack.com/archives/C01P0FRSXRV/p1715081387291119)
Author
Owner

@ITJamie commented on GitHub (May 8, 2024):

a quick workaround is to create empty files at the path it throws. eg /opt/netbox/netbox/scripts/add_gateways_to_prefixes.py in the above error.
if using a docker volume for that mountpoint its a little bit more involved.

@ITJamie commented on GitHub (May 8, 2024): a quick workaround is to create empty files at the path it throws. eg `/opt/netbox/netbox/scripts/add_gateways_to_prefixes.py` in the above error. if using a docker volume for that mountpoint its a little bit more involved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9616