Skip to content

fix(tasks): bypass Invoke PTY for interactive superuser/flush commands#12078

Open
getpwnam wants to merge 2 commits into
inventree:masterfrom
getpwnam:getpwnam/bugfix_invoke_pty_hang_clean
Open

fix(tasks): bypass Invoke PTY for interactive superuser/flush commands#12078
getpwnam wants to merge 2 commits into
inventree:masterfrom
getpwnam:getpwnam/bugfix_invoke_pty_hang_clean

Conversation

@getpwnam
Copy link
Copy Markdown

@getpwnam getpwnam commented Jun 3, 2026

Summary

This PR fixes an interactive CLI regression where invoke superuser (and interactive delete_data/flush) can drop the first typed character and then stall at the username/confirmation prompt in Docker terminal sessions.

The fix routes these specific interactive commands through a direct subprocess call (python3 manage.py ...) with inherited stdio instead of Invoke’s PTY execution path.

Closes: #11751

Problem

In affected Docker environments, running interactive commands via Invoke task execution shows:

  • First keypress is dropped (e.g. admin becomes dmin)
  • Prompt flow stalls after username/confirmation input
  • Superuser is not created

This was reproducible for:

docker compose run --rm inventree-server invoke superuser
docker compose exec -it inventree-server invoke superuser

But raw Django interactive command worked in the same container:

docker compose exec -it inventree-server python3 manage.py createsuperuser -v 0
That isolates the issue to the Invoke-mediated interactive path, not Django createsuperuser itself.

Reproduced Environment

  • Deployment: Docker Compose (contrib/container/docker-compose.yml)
  • Host OS: Debian 12 (bookworm)
  • InvenTree image tag: INVENTREE_TAG=1.3.0
  • Container runtime:
    • Python 3.14.3
    • invoke 2.2.1

Raw manage.py createsuperuser worked in the same environment, isolating the issue to the Invoke-mediated task path.

Why this happens

Invoke with pty=True performs its own stdin/TTY mediation (character-buffered input loop, stdin polling, PTY handling). In Docker interactive sessions, this adds an extra terminal mediation layer on top of Docker’s TTY handling. In some runtime combinations, this leads to input timing/forwarding issues (observed as dropped first character and prompt stalls).

Interactive input through the Invoke PTY path seems fragile here, while direct process stdio is stable.

Fix approach

For interactive management commands only:

  • Add manage_interactive(...) helper that executes python3 manage.py ... via subprocess.run(...) with inherited stdio.
  • Use manage_interactive('createsuperuser') in superuser.
  • Use manage_interactive('flush') for the interactive (non-force) delete_data path.
  • Non-interactive command paths remain unchanged and still use existing Invoke wrappers.

Why this is appropriate

Narrow scope: only touches commands that require interactive stdin behavior.
Preserves UX: invoke superuser remains interactive and now matches direct Django CLI behavior.
Evidence-based: raw Django interactive works in the same environment; only Invoke-mediated path fails.
Lower risk than broad task-runner changes.

Validation performed

Reproduced failure mode for invoke superuser in Docker interactive sessions.
Confirmed raw manage.py createsuperuser works in same environment.
Verified updated task code compiles and follows existing command error handling patterns.
Confirmed behaviour rationale in changelog update.

  • invoke superuser tested successfully (interactive input accepted correctly; no dropped first character; prompt flow completed).
  • invoke dev.delete-data tested successfully in interactive mode (confirmation input accepted correctly).

Files changed

  • tasks.py
  • CHANGELOG.md

Docker TTY sessions could drop the first keypress and stall at the username prompt when using invoke superuser (and interactive flush).

Run these interactive management commands via direct subprocess stdio instead of Invoke PTY mediation.

Refs inventree#11751.
@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 3, 2026

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 9b3d6cc
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a20aded312ac80008987e2c

@getpwnam getpwnam marked this pull request as ready for review June 3, 2026 21:45
@getpwnam getpwnam requested a review from SchrodingersGat as a code owner June 3, 2026 21:45
@matmair
Copy link
Copy Markdown
Member

matmair commented Jun 3, 2026

Hi @getpwnam ! Throwing walls of LLM-generated text against maintainers is a waste of everybody's time, waste of ressources and bad faith;

keep it short and human to avoid getting code-of-coducted on your next PR and in the following interactions.

Comment thread CHANGELOG.md Outdated
@matmair matmair added bug Identifies a bug which needs to be addressed setup Relates to the InvenTree setup / installation process labels Jun 3, 2026
@matmair matmair added this to the 1.3.4 milestone Jun 3, 2026
@SchrodingersGat SchrodingersGat requested a review from matmair June 4, 2026 12:46
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 setup Relates to the InvenTree setup / installation process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Superuser creation in CLI stucks as of version 1.3.x

2 participants