Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ITJamie opened this issue May 8, 2024 · 2 comments · Fixed by #16033
Closed
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@ITJamie
Copy link
Contributor

ITJamie commented May 8, 2024

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'
@ITJamie ITJamie added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels May 8, 2024
@ITJamie
Copy link
Contributor Author

ITJamie commented May 8, 2024

slack convo

@ITJamie ITJamie changed the title migration failure if old scripts exist in db that no longer exist on disk migration failure if old scripts exist in db that no longer exist on disk (0109_script_model) May 8, 2024
@ITJamie
Copy link
Contributor Author

ITJamie commented 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.

@DanSheps DanSheps added status: accepted This issue has been accepted for implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows and removed status: needs triage This issue is awaiting triage by a maintainer labels May 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants