Misleading error message from upgrade.sh if python is too old #5399

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

Originally created by @candlerb on GitHub (Sep 20, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.0.3

Python version

3.6 - 3.8

Steps to Reproduce

  1. Install Netbox v3 on an Ubuntu 18.04 system, which has the original python (3.6) and also python3.8 / python3.8-venv
  2. Run ./upgrade.sh

Expected Behavior

Upgrade should fail gracefully; user should be told up front that python 3.6 is too old before tearing down the old venv. Ideally it would also give the solution:

PYTHON=python3.8 ./upgrade.sh

Observed Behavior

upgrade.sh gets all the way through rebuilding the venv, and then aborts with this error when it tries to apply migrations:

--------------------------------------------------------------------
ERROR: Database schema migrations are out of synchronization. (No
data has been lost.) If attempting to upgrade to NetBox v3.0 or
later, first upgrade to a v2.11 release to ensure schema migrations
have been correctly prepared. For further detail on the exact error,
run the following commands:

    source /opt/netbox/venv/bin/activate
    python3 netbox/manage.py showmigrations
--------------------------------------------------------------------

That's a scary message, suggesting your database is in a messed-up state.

However, it's only if you run the "python3 netbox/manage.py showmigrations" command as shown that you'll see the real problem, which isn't to do with migrations at all:

(venv) root@netbox:/opt/netbox# python3 netbox/manage.py showmigrations
Traceback (most recent call last):
  File "netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute
    settings.INSTALLED_APPS
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/netbox/netbox/netbox/settings.py", line 30, in <module>
    f"NetBox requires Python 3.7 or higher (current: Python {platform.python_version()})"
RuntimeError: NetBox requires Python 3.7 or higher (current: Python 3.6.9)
Originally created by @candlerb on GitHub (Sep 20, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.0.3 ### Python version 3.6 - 3.8 ### Steps to Reproduce 1. Install Netbox v3 on an Ubuntu 18.04 system, which has the original python (3.6) and also python3.8 / python3.8-venv 2. Run `./upgrade.sh` ### Expected Behavior Upgrade should fail gracefully; user should be told up front that python 3.6 is too old before tearing down the old venv. Ideally it would also give the solution: ``` PYTHON=python3.8 ./upgrade.sh ``` ### Observed Behavior `upgrade.sh` gets all the way through rebuilding the venv, and then aborts with this error when it tries to apply migrations: ``` -------------------------------------------------------------------- ERROR: Database schema migrations are out of synchronization. (No data has been lost.) If attempting to upgrade to NetBox v3.0 or later, first upgrade to a v2.11 release to ensure schema migrations have been correctly prepared. For further detail on the exact error, run the following commands: source /opt/netbox/venv/bin/activate python3 netbox/manage.py showmigrations -------------------------------------------------------------------- ``` That's a scary message, suggesting your database is in a messed-up state. However, it's only if you run the "python3 netbox/manage.py showmigrations" command as shown that you'll see the *real* problem, which isn't to do with migrations at all: ``` (venv) root@netbox:/opt/netbox# python3 netbox/manage.py showmigrations Traceback (most recent call last): File "netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute settings.INSTALLED_APPS File "/opt/netbox/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 82, in __getattr__ self._setup(name) File "/opt/netbox/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 69, in _setup self._wrapped = Settings(settings_module) File "/opt/netbox/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 170, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/opt/netbox/netbox/netbox/settings.py", line 30, in <module> f"NetBox requires Python 3.7 or higher (current: Python {platform.python_version()})" RuntimeError: NetBox requires Python 3.7 or higher (current: Python 3.6.9) ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:27:29 +01:00
adam closed this issue 2025-12-29 19:27:29 +01:00
Author
Owner

@candlerb commented on GitHub (Sep 30, 2021):

There is another instance of this problem (with a different underlying exception) reported in discussion #7398.

I think it would be best to show the full underlying exception. The message about migrations could then be shown as a hint, perhaps only if the exception class is a specific Django ORM one.

@candlerb commented on GitHub (Sep 30, 2021): There is another instance of this problem (with a different underlying exception) reported in discussion #7398. I think it would be best to show the full underlying exception. The message about migrations could then be shown as a hint, perhaps only if the exception class is a specific Django ORM one.
Author
Owner

@jeremystretch commented on GitHub (Oct 1, 2021):

I'm just going to remove the message to avoid any confusion.

@jeremystretch commented on GitHub (Oct 1, 2021): I'm just going to remove the message to avoid any confusion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5399