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

Error on upgrade (docker container) #8460

Open
2 of 6 tasks
chl33 opened this issue Nov 9, 2024 · 6 comments
Open
2 of 6 tasks

Error on upgrade (docker container) #8460

chl33 opened this issue Nov 9, 2024 · 6 comments
Labels
bug Identifies a bug which needs to be addressed question This is a question

Comments

@chl33
Copy link

chl33 commented Nov 9, 2024

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

I tried to upgrade the database after updating docker containers, and got the errors pasted below instead of the usual successful update.

Steps to Reproduce

I'm using the latest inventree/inventree:stable docker image (sha256:19525ac2ccee0aa048f6b8cd717d2cc6e331e333cc1385a364eb453d84a74101).

  1. I shutdown the proxy, server, and worker docker containers.
  2. I run a version of the server container with command: invoke update

Expected behaviour

Usually this performs the upgrade successfully, then I restart the proxy, server, and worker containers.

Deployment Method

  • Docker
  • Package
  • Bare metal
  • Other - added info in Steps to Reproduce

Version Information

InvenTree Version	[0.16.8](https://github.com/inventree/InvenTree/releases)Up to Date
InvenTree Documentation	https://docs.inventree.org/en/0.16.8
API Version	[232](https://inventree.go-robo.net/api-doc/)
Python Version	3.11.9
Django Version	[4.2.15](https://www.djangoproject.com/)
View Code on GitHub	https://github.com/InvenTree/InvenTree/
Credits	https://docs.inventree.org/en/latest/credits/
Mobile App	https://docs.inventree.org/app/
Submit Bug Report	[https://github.com/InvenTree/InvenTree/issues](https://github.com/InvenTree/InvenTree//issues)

Please verify if you can reproduce this bug on the demo site.

  • I can reproduce this bug on the demo site.

Relevant log output

Python version 3.11.9 - /usr/local/bin/python3

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

/usr/local/lib/python3.11/site-packages/allauth/exceptions.py:9: UserWarning: allauth.exceptions is deprecated, use allauth.core.exceptions

  warnings.warn("allauth.exceptions is deprecated, use allauth.core.exceptions")

Backing up InvenTree database...

Python version 3.11.9 - /usr/local/bin/python3

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

Traceback (most recent call last):

  File "/home/inventree/src/backend/InvenTree/manage.py", line 24, in <module>

    main()

  File "/home/inventree/src/backend/InvenTree/manage.py", line 20, in main

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 275, in fetch_command

    klass = load_command_class(app_name, subcommand)

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 48, in load_command_class

    module = import_module("%s.management.commands.%s" % (app_name, name))

             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load

  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 940, in exec_module

  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

  File "/root/.local/lib/python3.11/site-packages/dbbackup/management/commands/dbbackup.py", line 9, in <module>

    from ...storage import StorageError, get_storage

  File "/root/.local/lib/python3.11/site-packages/dbbackup/storage.py", line 7, in <module>

    from django.core.files.storage import get_storage_class

ImportError: cannot import name 'get_storage_class' from 'django.core.files.storage' (/usr/local/lib/python3.11/site-packages/django/core/files/storage/__init__.py)w
@chl33 chl33 added bug Identifies a bug which needs to be addressed question This is a question triage:not-checked Item was not checked by the core team labels Nov 9, 2024
@matmair matmair removed the triage:not-checked Item was not checked by the core team label Nov 9, 2024
@SchrodingersGat
Copy link
Member

Can you try running invoke install and then invoke update?

@chl33
Copy link
Author

chl33 commented Nov 10, 2024

I switched the command entry in my docker compose file to sh -c 'invoke install && invoke update'.

Requirement already satisfied: weasyprint==61.2 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1615)) (61.2)

Requirement already satisfied: webencodings==0.5.1 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1621)) (0.5.1)

Requirement already satisfied: whitenoise==6.7.0 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1629)) (6.7.0)

Requirement already satisfied: wrapt==1.16.0 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1633)) (1.16.0)

Requirement already satisfied: xlrd==2.0.1 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1708)) (2.0.1)

Requirement already satisfied: xlwt==1.3.0 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1712)) (1.3.0)

Requirement already satisfied: xmlsec==1.3.14 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1716)) (1.3.14)

Requirement already satisfied: zipp==3.19.2 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1776)) (3.19.2)

Requirement already satisfied: zopfli==0.2.3 in /root/.local/lib/python3.11/site-packages (from -r src/backend/requirements.txt (line 1780)) (0.2.3)

Building wheels for collected packages: django-allauth

  Building wheel for django-allauth (pyproject.toml): started

  Building wheel for django-allauth (pyproject.toml): finished with status 'done'

  Created wheel for django-allauth: filename=django_allauth-0.63.3-py3-none-any.whl size=1420666 sha256=649af8d2990db85e342b863719e86cf3fdafd024a176f9063fea2d35e16ceea0

  Stored in directory: /tmp/pip-ephem-wheel-cache-564064mt/wheels/e8/ed/41/ca3a3b6bb42af977e33296c1420d3a361a5338e73535cca890

Successfully built django-allauth

Installing collected packages: setuptools, django, django-allauth

  Attempting uninstall: setuptools

    Found existing installation: setuptools 75.3.0

    Uninstalling setuptools-75.3.0:

      Successfully uninstalled setuptools-75.3.0

  Attempting uninstall: django

    Found existing installation: Django 5.1.3

    Uninstalling Django-5.1.3:

      Successfully uninstalled Django-5.1.3

  Attempting uninstall: django-allauth

    Found existing installation: django-allauth 65.2.0

    Uninstalling django-allauth-65.2.0:

      Successfully uninstalled django-allauth-65.2.0

Successfully installed django-4.2.15 django-allauth-0.63.3 setuptools-72.1.0

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.

Installing plugin packages from '/home/inventree/data/plugins.txt'

Requirement already satisfied: inventree-brother-plugin in /usr/local/lib/python3.11/site-packages (from -r /home/inventree/data/plugins.txt (line 2)) (1.0.0)

Requirement already satisfied: django-allauth in /usr/local/lib/python3.11/site-packages (from -r /home/inventree/data/plugins.txt (line 3)) (0.63.3)

Collecting django-allauth (from -r /home/inventree/data/plugins.txt (line 3))

  Using cached django_allauth-65.2.0-py3-none-any.whl

Requirement already satisfied: brother-ql-inventree>=1.1 in /usr/local/lib/python3.11/site-packages (from inventree-brother-plugin->-r /home/inventree/data/plugins.txt (line 2)) (1.3)

Collecting Django>=4.2.16 (from django-allauth->-r /home/inventree/data/plugins.txt (line 3))

  Using cached Django-5.1.3-py3-none-any.whl.metadata (4.2 kB)

Requirement already satisfied: asgiref>=3.8.1 in /root/.local/lib/python3.11/site-packages (from django-allauth->-r /home/inventree/data/plugins.txt (line 3)) (3.8.1)

Requirement already satisfied: click in /usr/local/lib/python3.11/site-packages (from brother-ql-inventree>=1.1->inventree-brother-plugin->-r /home/inventree/data/plugins.txt (line 2)) (8.1.7)

Requirement already satisfied: packbits in /usr/local/lib/python3.11/site-packages (from brother-ql-inventree>=1.1->inventree-brother-plugin->-r /home/inventree/data/plugins.txt (line 2)) (0.6)

Requirement already satisfied: pillow>=10.0.0 in /root/.local/lib/python3.11/site-packages (from brother-ql-inventree>=1.1->inventree-brother-plugin->-r /home/inventree/data/plugins.txt (line 2)) (10.3.0)

Requirement already satisfied: pyusb in /usr/local/lib/python3.11/site-packages (from brother-ql-inventree>=1.1->inventree-brother-plugin->-r /home/inventree/data/plugins.txt (line 2)) (1.2.1)

Requirement already satisfied: attrs in /root/.local/lib/python3.11/site-packages (from brother-ql-inventree>=1.1->inventree-brother-plugin->-r /home/inventree/data/plugins.txt (line 2)) (23.2.0)

Requirement already satisfied: sqlparse>=0.3.1 in /root/.local/lib/python3.11/site-packages (from Django>=4.2.16->django-allauth->-r /home/inventree/data/plugins.txt (line 3)) (0.5.0)

Using cached Django-5.1.3-py3-none-any.whl (8.3 MB)

Installing collected packages: Django, django-allauth

  Attempting uninstall: Django

    Found existing installation: Django 4.2.15

    Uninstalling Django-4.2.15:

      Successfully uninstalled Django-4.2.15

  Attempting uninstall: django-allauth

    Found existing installation: django-allauth 0.63.3

    Uninstalling django-allauth-0.63.3:

      Successfully uninstalled django-allauth-0.63.3

Successfully installed Django-5.1.3 django-allauth-65.2.0

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.

Python version 3.11.9 - /usr/local/bin/python3

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

/usr/local/lib/python3.11/site-packages/allauth/exceptions.py:9: UserWarning: allauth.exceptions is deprecated, use allauth.core.exceptions

  warnings.warn("allauth.exceptions is deprecated, use allauth.core.exceptions")

Backing up InvenTree database...

Python version 3.11.9 - /usr/local/bin/python3

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

Traceback (most recent call last):

  File "/home/inventree/src/backend/InvenTree/manage.py", line 24, in <module>

    main()

  File "/home/inventree/src/backend/InvenTree/manage.py", line 20, in main

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 275, in fetch_command

    klass = load_command_class(app_name, subcommand)

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 48, in load_command_class

    module = import_module("%s.management.commands.%s" % (app_name, name))

             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load

  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 940, in exec_module

  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

  File "/root/.local/lib/python3.11/site-packages/dbbackup/management/commands/dbbackup.py", line 9, in <module>

    from ...storage import StorageError, get_storage

  File "/root/.local/lib/python3.11/site-packages/dbbackup/storage.py", line 7, in <module>

    from django.core.files.storage import get_storage_class

ImportError: cannot import name 'get_storage_class' from 'django.core.files.storage' (/usr/local/lib/python3.11/site-packages/django/core/files/storage/__init__.py)

@SchrodingersGat
Copy link
Member

Are you just using the regular docker setup? From the log files it appears that installation process is installing the wrong version of django:

Successfully installed Django-5.1.3 django-allauth-65.2.0

Whereas we are pinned at a lower version:

Image

@chl33
Copy link
Author

chl33 commented Nov 10, 2024

This is my docker-compose setup:

version: "3.8"

# Docker compose recipe for a production-ready InvenTree setup, with the following containers:
# - PostgreSQL as the database backend
# - gunicorn as the InvenTree web server
# - django-q as the InvenTree background worker process
# - nginx as a reverse proxy
# - redis as the cache manager (optional, disabled by default)

# ---------------------
# READ BEFORE STARTING!
# ---------------------

# -----------------------------
# Setting environment variables
# -----------------------------
# Shared environment variables should be stored in the .env file
# Changes made to this file are reflected across all containers!
#
# IMPORTANT NOTE:
# You should not have to change *anything* within this docker-compose.yml file!
# Instead, make any changes in the .env file!

# ------------------------
# InvenTree Image Versions
# ------------------------
# By default, this docker-compose script targets the STABLE version of InvenTree,
# image: inventree/inventree:stable
#
# To run the LATEST (development) version of InvenTree,
# change the INVENTREE_TAG variable (in the .env file) to "latest"
#
# Alternatively, you could target a specific tagged release version with (for example):
# INVENTREE_TAG=0.7.5
#

services:
    # Database service
    # Use PostgreSQL as the database backend
    inventree-db:
        image: postgres:13
        expose:
            - ${INVENTREE_DB_PORT:-5432}/tcp
        environment:
            - PGDATA=/var/lib/postgresql/data/pgdb
            - POSTGRES_USER=${INVENTREE_DB_USER:?You must provide the 'INVENTREE_DB_USER' variable in the .env file}
            - POSTGRES_PASSWORD=${INVENTREE_DB_PASSWORD:?You must provide the 'INVENTREE_DB_PASSWORD' variable in the .env file}
            - POSTGRES_DB=${INVENTREE_DB_NAME:?You must provide the 'INVENTREE_DB_NAME' variable in the .env file}
        volumes:
            # Map 'data' volume such that postgres database is stored externally
            - inventree_data:/var/lib/postgresql/data/
        restart: unless-stopped
        networks:
            - inventree-network

    # redis acts as database cache manager
    # only runs under the "redis" profile : https://docs.docker.com/compose/profiles/
    inventree-cache:
        image: redis:7.0
        depends_on:
            - inventree-db
        profiles:
            - redis
        env_file:
            - stack.env
        expose:
            - ${INVENTREE_CACHE_PORT:-6379}
        restart: always
        networks:
            - inventree-network

    # InvenTree web server service
    # Uses gunicorn as the web server
    inventree-server:
        # If you wish to specify a particular InvenTree version, do so here
        image: inventree/inventree:${INVENTREE_TAG:-stable}
        #image: inventree/inventree:0.12.10
        # Only change this port if you understand the stack.
        # If you change this you have to change:
        # - the proxy settings (on two lines)
        # - only change the exposed port - eg `1338:8000` if you want to expose the server on port 1338
        expose:
            - 8000
        depends_on:
            - inventree-db
        env_file:
            - stack.env
        volumes:
            # Data volume must map to /home/inventree/data
            - inventree_data:/home/inventree/data
        restart: unless-stopped
        networks:
            - inventree-network

    # A container to run to upgrade Inventree's db on new releases
    inventree-server-upgrade:
        image: inventree/inventree:${INVENTREE_TAG:-stable}
        command: sh -c 'invoke install && invoke update'
        expose:
            - 8000
        depends_on:
            - inventree-db
        env_file:
            - stack.env
        volumes:
            # Data volume must map to /home/inventree/data
            - inventree_data:/home/inventree/data
        networks:
            - inventree-network

    # Background worker process handles long-running or periodic tasks
    inventree-worker:
        # If you wish to specify a particular InvenTree version, do so here
        image: inventree/inventree:${INVENTREE_TAG:-stable}
        #image: inventree/inventree:0.12.10
        command: invoke worker
        depends_on:
            - inventree-server
        env_file:
            - stack.env
        volumes:
            # Data volume must map to /home/inventree/data
            - inventree_data:/home/inventree/data
        restart: unless-stopped
        networks:
            - inventree-network

    # nginx acts as a reverse proxy
    # static files are served directly by nginx
    # media files are served by nginx, although authentication is redirected to inventree-server
    # web requests are redirected to gunicorn
    # NOTE: You will need to provide a working nginx.conf file!
    inventree-proxy:
        image: nginx:stable
        depends_on:
            - inventree-server
        env_file:
            - stack.env
        ports:
            # Default web port is 1337 (can be changed in the .env file)
            - ${INVENTREE_WEB_PORT:-1337}:80
        volumes:
            # Provide nginx configuration file to the container
            # Refer to the provided example file as a starting point
            - /opt/config/inventree/nginx/nginx.prod.conf:/etc/nginx/conf.d/default.conf:ro
            # nginx proxy needs access to static and media files
            - inventree_data:/var/www
        restart: unless-stopped
        networks:
            - inventree-network
            - swag-network

volumes:
    # Persistent data, stored external to the container(s)
    inventree_data:
        driver: local
        driver_opts:
            type: none
            o: bind
            # This directory specified where InvenTree data are stored "outside" the docker containers
            device: ${INVENTREE_EXT_VOLUME:?You must specify the 'INVENTREE_EXT_VOLUME' variable in the .env file!}

networks:
  swag-network:
    external: true
  inventree-network:
    external: true

@matmair
Copy link
Member

matmair commented Nov 11, 2024

This is indeed very interesting. I am out of ideas how these install targets are acquired - none of our branches point to those. @chl33 are you running a fork?

@chl33
Copy link
Author

chl33 commented Nov 12, 2024

I'm not running a fork. I'm just using the docker images specified in the docker-compose configuration posted above. I'll try to spend some time this weekend to look at the image and see if I can figure anything out about why a different version of Django is being installed.

Thank you for this software and for looking at this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies a bug which needs to be addressed question This is a question
Projects
None yet
Development

No branches or pull requests

3 participants