[Django] #34535: dbshell management command can crash if DATABASES["name"] is a PosixPath

1 view
Skip to first unread message

Django

unread,
May 3, 2023, 9:32:59 AM5/3/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan | Owner: nobody
Pieter Waagmeester |
Type: Bug | Status: new
Component: Core | Version: 4.2
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34535>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 3, 2023, 9:36:45 AM5/3/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan Pieter | Owner: Jan
Waagmeester | Pieter Waagmeester
Type: Bug | Status: assigned
Component: Core (Management | Version: 4.2
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

* owner: nobody => Jan Pieter Waagmeester
* status: new => assigned
* has_patch: 0 => 1
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted


Comment:

felix will update the name to be specific to the error

--
Ticket URL: <https://code.djangoproject.com/ticket/34535#comment:1>

Django

unread,
May 3, 2023, 9:38:24 AM5/3/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan Pieter | Owner: Jan
Waagmeester | Pieter Waagmeester
Type: Bug | Status: assigned
Component: Core (Management | Version: 4.2
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by David Sanders):

PR: https://github.com/django/django/pull/16824

--
Ticket URL: <https://code.djangoproject.com/ticket/34535#comment:2>

Django

unread,
May 3, 2023, 10:31:48 AM5/3/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan Pieter | Owner: Jan
Waagmeester | Pieter Waagmeester
Type: Bug | Status: assigned
Component: Core (Management | Version: 4.2
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jan Pieter Waagmeester):

* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/34535#comment:3>

Django

unread,
May 3, 2023, 11:24:14 AM5/3/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan Pieter | Owner: Jan
Waagmeester | Pieter Waagmeester
Type: Bug | Status: assigned
Component: Core (Management | Version: 4.2
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Adam Johnson (added)


Comment:

Regression in 5b884d45ac5b76234eca614d90c83b347294c332.

--
Ticket URL: <https://code.djangoproject.com/ticket/34535#comment:4>

Django

unread,
May 4, 2023, 12:08:49 AM5/4/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan Pieter | Owner: Jan
Waagmeester | Pieter Waagmeester
Type: Bug | Status: assigned
Component: Core (Management | Version: 4.2
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34535#comment:5>

Django

unread,
May 4, 2023, 1:55:41 AM5/4/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan Pieter | Owner: Jan
Waagmeester | Pieter Waagmeester
Type: Bug | Status: closed

Component: Core (Management | Version: 4.2
commands) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f5b39b77e38b7585861df9314aba4ce93b018c4c" f5b39b7]:
{{{
#!CommitTicketReference repository=""
revision="f5b39b77e38b7585861df9314aba4ce93b018c4c"
Fixed #34535 -- Fixed SQLite dbshell crash on pathlib.Path when handling
CommandError.

Regression in 5b884d45ac5b76234eca614d90c83b347294c332.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34535#comment:6>

Django

unread,
May 25, 2023, 4:06:23 PM5/25/23
to django-...@googlegroups.com
#34535: dbshell management command can crash if DATABASES["name"] is a PosixPath
-------------------------------------+-------------------------------------
Reporter: Jan Pieter | Owner: Jan
Waagmeester | Pieter Waagmeester
Type: Bug | Status: closed
Component: Core (Management | Version: 4.2
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adam Johnson):

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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34535#comment:7>

Reply all
Reply to author
Forward
0 new messages