#37109 assigned Cleanup/optimization

Suppress KeyboardInterrupt traceback in dbshell

Reported by: Vikash G Owned by: Vikash G
Component: Core (Management commands) Version: 6.0
Severity: Normal Keywords:
Cc: Vikash G Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When running python manage.py dbshell and exiting with Ctrl+C,
Django prints a full traceback originating from subprocess.run().

This is reproducible with the SQLite backend on Python 3.13.

Example:

$ python manage.py dbshell

SQLite version 3.51.0
sqlite> [pressed Ctrl + C]

Traceback (most recent call last):
  ...
  File ".../django/db/backends/base/client.py", line 31, in runshell
    subprocess.run(args, env=env, check=True)
  ...
KeyboardInterrupt

Expected behavior:

dbshell should terminate cleanly without displaying a traceback
when interrupted with Ctrl+C, since this is normal interactive shell
behavior.

The issue appears to come from subprocess.run() propagating
KeyboardInterrupt during interactive shell execution.

A possible fix is to suppress KeyboardInterrupt around the
subprocess.run() call in:

django/db/backends/base/client.py

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top