#34535 closed Bug (fixed)
dbshell management command can crash if DATABASES["name"] is a PosixPath
Reported by: | Jan Pieter Waagmeester | Owned by: | Jan Pieter Waagmeester |
---|---|---|---|
Component: | Core (Management commands) | Version: | 4.2 |
Severity: | Normal | Keywords: | |
Cc: | Adam Johnson | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
With a sqlite database configured in settings.py
like this:
DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": BASE_DIR / "db.sqlite3", } }
exiting ./manage.py dbshell
using Control - d
sometimes results in this exception:
Traceback (most recent call last): File "/home/ubuntu/virtualenv/lib/python3.11/site-packages/django/core/management/commands/dbshell.py", line 30, in handle connection.client.runshell(options["parameters"]) File "/home/ubuntu/virtualenv/lib/python3.11/site-packages/django/db/backends/base/client.py", line 28, in runshell subprocess.run(args, env=env, check=True) File "/usr/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['sqlite3', PosixPath('/home/ubuntu/planning-poker/db.sqlite3')]' returned non-zero exit status 1. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/planning-poker/./manage.py", line 30, in <module> main() File "/home/ubuntu/planning-poker/./manage.py", line 26, in main execute_from_command_line(sys.argv) File "/home/ubuntu/virtualenv/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/home/ubuntu/virtualenv/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/ubuntu/virtualenv/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv self.execute(*args, **cmd_options) File "/home/ubuntu/virtualenv/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute output = self.handle(*args, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/virtualenv/lib/python3.11/site-packages/django/core/management/commands/dbshell.py", line 44, in handle " ".join(e.cmd), ^^^^^^^^^^^^^^^ TypeError: sequence item 1: expected str instance, PosixPath found
coercing each item in e.cmd
to string should fix this.
Change History (7)
comment:1 by , 20 months ago
Has patch: | set |
---|---|
Needs tests: | set |
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 20 months ago
Needs tests: | unset |
---|
comment:5 by , 20 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:7 by , 19 months ago
I also just hit this. Thanks for the fix.
For completeness, the "sometimes" depends on the exit code of SQLite, which is non-zero if the last run query was an error, for example:
$ ./manage.py dbshell SQLite version 3.39.5 2022-10-14 20:58:05 Enter ".help" for usage hints. sqlite> select; Parse error: near ";": syntax error select; ^--- error here sqlite> ^D Traceback (most recent call last): ... TypeError: sequence item 1: expected str instance, PosixPath found
Note:
See TracTickets
for help on using tickets.
felix will update the name to be specific to the error