Skip to content

Plugin installation skipped after container replacement because _PLUGIN_FILE_HASH survives the Python environment #12848

Closed

Description

@kquinsland01

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

I am running Inventree in kubernetes and have found a bug with how plugins.txt works.
You don't need to be using kubernetes for this bug, any "one database, multiple distinct python venvs" setup will have this issue.

How I found the bug:

On an existing/running install, I added the mcp plugin so I could quickly test a few things out.

During routine cluster maintenance (drain one node at a time, update, re-join cluster), Inventree was re-instantiated onto a new node and when the new instance came up, the mcp plugin was not loaded.

The database and plugins.txt persist, but the container's Python packages do not.

It took a bit of digging but it looks like the root cause is the previously stored _PLUGIN_FILE_HASH matches the requirements file and returns without checking whether the packages exist in the current Python environment.

The documented container installation behavior suggests that enabling Check Plugins on Startup should handle ephemeral plugin environments but that does not happen in all cases.

After inventree restarts, the plugin is not installed and it shows up as not installed when I visit the /web/settings/admin/plugin/ page.

TL;DR: With Check Plugins on Startup enabled, replacing an InvenTree container can leave configured plugins uninstalled.

It looks like this "shallow check" behavior is new: PR #12776 moved the installer guard from process-local state to a database-backed _PLUGIN_FILE_HASH and added a shared lease.

A database-wide hash cannot establish that packages are installed in every Python environment using the database (web server/core and the worker node(s) ).

Steps to Reproduce

I use podman but I have it aliased to docker; this should be copy/paste / ready to show the issue.

❯ mkdir -p /tmp/inventree-plugin-repro
❯ cd /tmp/inventree-plugin-repro

❯ curl -fsSLO https://raw.githubusercontent.com/inventree/InvenTree/master/contrib/container/docker-compose.yml 
❯ curl -fsSLO https://raw.githubusercontent.com/inventree/InvenTree/master/contrib/container/.env 

❯ cp .env .envORIG
'.env' -> '.envORIG'

# Make minimal changes
❯ diff .env .envORIG
9c9
< INVENTREE_TAG=1.5.4
---
> INVENTREE_TAG=stable
35c35
< INVENTREE_LOG_LEVEL=INFO
---
> INVENTREE_LOG_LEVEL=WARNING

Then prep for first launch:

❯ docker compose pull inventree-db inventree-cache inventree-server inventree-worker
❯ docker compose up -d --wait inventree-db inventree-cache
[+] Running 3/3
 ✔ Network inventree_default  Created                                                                         0.0s 
 ✔ Container inventree-cache  Healthy                                                                         1.4s 
 ✔ Container inventree-db     Healthy                                                                        16.9s 

❯ docker compose run --rm --no-deps inventree-server invoke update
# <...> This takes ... A WHILE to run for the first time!
Settings cleaned successfully

Install plugin:

# Sorry for the 1 liner... whitespace breaks it otherwise!
❯ docker compose run --rm --no-deps inventree-server python /home/inventree/src/backend/InvenTree/manage.py shell -c 'from django.conf import settings; from common.models import InvenTreeSetting; InvenTreeSetting.set_setting("PLUGIN_ON_STARTUP", True); settings.PLUGIN_FILE.write_text("inventree-mcp==0.2.2\n"); print("Requirements file:", settings.PLUGIN_FILE)'
# <...>
113 objects imported automatically (use -v 2 for details).

Requirements file: /home/inventree/data/plugins.txt

I'll use this script going forward:

❯ cat check-plugins.sh
#!/usr/bin/env bash
set -euo pipefail

if command -v podman >/dev/null 2>&1; then
  container_engine=podman
elif command -v docker >/dev/null 2>&1; then
  container_engine=docker
else
  printf 'Error: neither podman nor docker is available in PATH.\n' >&2
  exit 1
fi

if ! "$container_engine" compose version >/dev/null 2>&1; then
  printf 'Error: %s compose is not available.\n' "$container_engine" >&2
  exit 1
fi

if ! compose_services=$("$container_engine" compose config --services); then
  printf 'Error: run this script from your configured Compose directory.\n' >&2
  exit 1
fi

if (( $# == 0 )); then
  set -- inventree-server inventree-worker
fi

status=0
for service in "$@"; do
  if [[ ! "$service" =~ ^[a-zA-Z0-9][a-zA-Z0-9_.-]*$ ]] ||
    [[ $'\n'"$compose_services"$'\n' != *$'\n'"$service"$'\n'* ]]; then
    printf 'Error: unknown Compose service: %s\n' "$service" >&2
    status=1
    continue
  fi

  printf '\nService: %s\n' "$service"
  if ! "$container_engine" compose exec -T "$service" python - <<'PY'
import hashlib
import sys
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

try:
    print("inventree-mcp:", version("inventree-mcp"))
except PackageNotFoundError:
    print("inventree-mcp: MISSING")

path = Path("/home/inventree/data/plugins.txt")
try:
    contents = path.read_bytes()
except OSError as error:
    print(f"Error reading {path}: {error}", file=sys.stderr)
    sys.exit(1)

print("plugins.txt:", repr(contents.decode("utf-8", errors="replace")))
print("file hash:", hashlib.sha256(contents).hexdigest())
PY
  then
    printf 'Error: could not complete inspection of %s.\n' "$service" >&2
    status=1
  fi
done

exit "$status"

Then start and do install:

❯ docker compose up -d --wait --wait-timeout 300 inventree-server
❯ ./check-plugins.sh

Service: inventree-server
inventree-mcp: 0.2.2
plugins.txt: 'inventree-mcp==0.2.2\n'
file hash: 03580a9e0cf60dd59ec04bfe1e55100ee2bd252c5acbd3c14ae95ea09bf22e49

Service: inventree-worker
service "inventree-worker" is not running
Error: executing /usr/local/bin/docker-compose exec -T inventree-worker python -: exit status 1
Error: could not complete inspection of inventree-worker.

May as well check what's in the DB:

# Note: I use podman, change as needed
❯ printf '%s\n' "SELECT key, value FROM common_inventreesetting WHERE key IN ('PLUGIN_ON_STARTUP', '_PLUGIN_FILE_HASH');" | podman compose exec -T inventree-db sh -c 'exec psql -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
        key        |                              value                               
-------------------+------------------------------------------------------------------
 PLUGIN_ON_STARTUP | True
 _PLUGIN_FILE_HASH | 03580a9e0cf60dd59ec04bfe1e55100ee2bd252c5acbd3c14ae95ea09bf22e49
(2 rows)

Then start up second container and show the issue:

❯ docker compose up -d --wait --wait-timeout 300 inventree-worker
❯ ./check-plugins.sh

Service: inventree-server
inventree-mcp: 0.2.2
plugins.txt: 'inventree-mcp==0.2.2\n'
file hash: 03580a9e0cf60dd59ec04bfe1e55100ee2bd252c5acbd3c14ae95ea09bf22e49

Service: inventree-worker
inventree-mcp: MISSING
plugins.txt: 'inventree-mcp==0.2.2\n'
file hash: 03580a9e0cf60dd59ec04bfe1e55100ee2bd252c5acbd3c14ae95ea09bf22e49

And then show how it'll go MISSING in any future container, too:

# This mimics the same thing that k8s does when a workload is migrated or restarted
❯ docker compose up -d --no-deps --force-recreate --wait --wait-timeout 300 inventree-server
# Boom
❯ ./check-plugins.sh

Service: inventree-server
inventree-mcp: MISSING
plugins.txt: 'inventree-mcp==0.2.2\n'
file hash: 03580a9e0cf60dd59ec04bfe1e55100ee2bd252c5acbd3c14ae95ea09bf22e49

Service: inventree-worker
inventree-mcp: MISSING
plugins.txt: 'inventree-mcp==0.2.2\n'
file hash: 03580a9e0cf60dd59ec04bfe1e55100ee2bd252c5acbd3c14ae95ea09bf22e49

Expected behaviour

Each Python environment should satisfy the plugin requirements before its service starts, including after container replacement.

Ideally an unchanged requirements file should only skip installation when the current environment already satisfies it.

Deployment Method

Other - added info in Steps to Reproduce

Version Information

InvenTree-Version: 1.5.4
Django Version: 5.2.16
Commit Hash: d2db7b1
Commit Date: 2026-09-09
Commit Branch: null
Database: django.db.backends.postgresql
Debug-Mode: False
Deployed using Docker: True
Platform: Linux-6.8.0-55-generic-x86_64-with-glibc2.41
Installer: DOC
Active plugins: [{"name":"InvenTreeBarcode","slug":"inventreebarcode","version":"2.2.0"},{"name":"BOM Exporter","slug":"bom-exporter","version":"1.1.0"},{"name":"InvenTree Exporter","slug":"inventree-exporter","version":"1.0.0"},{"name":"Parameter Exporter","slug":"parameter-exporter","version":"2.0.0"},{"name":"InvenTreeEmailNotifications","slug":"inventree-email-notification","version":"1.0.0"},{"name":"InvenTreeUINotifications","slug":"inventree-ui-notification","version":"1.0.0"},{"name":"InvenTreeCurrencyExchange","slug":"inventreecurrencyexchange","version":"1.0.0"},{"name":"InvenTreeMachines","slug":"inventree-machines","version":"1.0.0"},{"name":"InvenTreeLabel","slug":"inventreelabel","version":"1.1.0"},{"name":"InvenTreeLabelMachine","slug":"inventreelabelmachine","version":"1.0.0"}]


  • InvenTree 1.5.4, official inventree/inventree image.
  • Image digest: sha256:a946ec09da3e5a5b7343fb7d02f2367f74167f4ce883a62e4a313db7bdb9bd54.
  • Python 3.14.
  • Kubernetes, separate web-server and background-worker containers.
  • Persistent PostgreSQL database and /home/inventree/data volume.
  • Python package installations are container-local; no persistent virtual environment.
  • PLUGIN_ON_STARTUP=True and plugin support enabled.

The persistent requirements file contains:

inventree-brother-plugin
inventree-zebra-plugin
inventree-mcp

Try to reproduce on the demo site

I did not try to reproduce

Is the bug reproducible on the demo site?

Not reproducible

Relevant log output

I have reviewed this report for correctness and filled out all sections.

  • I have checked this report. I acknowledge that filing bugs via AI agents without review might lead to being blocked.

Activity

  1. added
    bug
    question
    on Sep 13, 2026
  2. added theissue type on Sep 13, 2026
  3. added
    triage:not-checked
    on Sep 13, 2026
  4. kquinsland01 commented on Sep 13, 2026

    @kquinsland01
    ContributorAuthor

    I have a work-around but it's inelegant.
    This script is mounted into the pod @ /etc/inventree/start-with-plugins.py:

    """Install plugins in this container, then replace this process with the service.
    
    Usage: python /etc/inventree/start-with-plugins.py <service command> [arguments...]
    Run after the image's init.sh so Python uses its selected environment. Installs
    Git-required plugins plus the existing UI-managed requirements on the PVC into
    the container's Python environment. Installation failure prevents service startup.
    No database access, shared install marker, or plugin-file mutation is involved.
    """
    
    import os
    from pathlib import Path
    import subprocess
    import sys
    
    REQUIRED_PLUGINS = Path(__file__).with_name("plugins.txt")
    # This deployment uses the default plugin file alongside its persistent config.
    USER_PLUGINS = Path("/home/inventree/data/plugins.txt")
    
    
    def main():
        if len(sys.argv) < 2:
            raise SystemExit("A service command is required")
    
        command = [sys.executable, "-m", "pip", "install", "--disable-pip-version-check",
                   "--no-cache-dir", "--requirement", str(REQUIRED_PLUGINS)]
        if USER_PLUGINS.exists():
            command += ["--requirement", str(USER_PLUGINS)]
    
        print("Installing required and user-managed plugins in this container", flush=True)
        subprocess.run(command, check=True)
        os.execvp(sys.argv[1], sys.argv[1:])
    
    
    if __name__ == "__main__":
        main()

    And then in both the server and worker deployment, I am doing this:

    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
        name: inventree-server
    spec:
        replicas: 1
           # <...>
            spec:
                # The VERY FIRST TIME that inventree is started, we need to manually run a few commands.
                # Ideally this is something that the init script would handle for us. Currently doing manually
                # TODO: work-around this w/ an initContainer or file upstream bug
                containers:
                    - name: inventree-server
                      image: kustomize-inventree:latest
                      imagePullPolicy: Always
                      # Keep init.sh, then install plugins before the image's normal Gunicorn command.
                      # The database's plugin-file hash survives replacement; Python packages do not.
                      # See: https://github.com/inventree/InvenTree/issues/12848
                      args:
                          - python
                          - /etc/inventree/start-with-plugins.py
                          - sh
                          - -c
                          - exec gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} --chdir ${INVENTREE_BACKEND_DIR}/InvenTree
  5. SchrodingersGat commented on Sep 15, 2026

    @SchrodingersGat
    Member

    @kquinsland thanks for reporting - please review #12858

  6. kquinsland01 commented on Sep 15, 2026

    @kquinsland01
    ContributorAuthor

    Also store the hash as a local marker file in the current environment

    Oh that's a simpler way to do it. When I wrote this issue up the other day I could only think of less clean way to do this.

  7. removed
    question
    triage:not-checked
    on Sep 15, 2026
  8. added this to the 1.5.5 milestone on Sep 15, 2026
  9. added
    plugin
    docker
    setup
    on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdockerpluginsetup

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions