summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Pieter Waagmeester <jieter@jieter.nl>2023-05-03 14:24:45 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-05-04 06:07:12 +0200
commitf5b39b77e38b7585861df9314aba4ce93b018c4c (patch)
tree69cfa98dbbfcc98a2526d76106954f544c41369c
parent49830025c992fbc8d8f213e7c16dba1391c6adf2 (diff)
downloaddjango-f5b39b77e38b7585861df9314aba4ce93b018c4c.tar.gz
Fixed #34535 -- Fixed SQLite dbshell crash on pathlib.Path when handling CommandError.
Regression in 5b884d45ac5b76234eca614d90c83b347294c332.
-rw-r--r--django/core/management/commands/dbshell.py2
-rw-r--r--tests/dbshell/test_sqlite.py19
2 files changed, 20 insertions, 1 deletions
diff --git a/django/core/management/commands/dbshell.py b/django/core/management/commands/dbshell.py
index 30d2765afb..bdb130594f 100644
--- a/django/core/management/commands/dbshell.py
+++ b/django/core/management/commands/dbshell.py
@@ -41,7 +41,7 @@ class Command(BaseCommand):
raise CommandError(
'"%s" returned non-zero exit status %s.'
% (
- " ".join(e.cmd),
+ " ".join(map(str, e.cmd)),
e.returncode,
),
returncode=e.returncode,
diff --git a/tests/dbshell/test_sqlite.py b/tests/dbshell/test_sqlite.py
index 7c39fd111e..faf9882ad9 100644
--- a/tests/dbshell/test_sqlite.py
+++ b/tests/dbshell/test_sqlite.py
@@ -1,5 +1,9 @@
+import subprocess
from pathlib import Path
+from unittest import mock, skipUnless
+from django.core.management import CommandError, call_command
+from django.db import connection
from django.db.backends.sqlite3.client import DatabaseClient
from django.test import SimpleTestCase
@@ -21,3 +25,18 @@ class SqliteDbshellCommandTestCase(SimpleTestCase):
self.settings_to_cmd_args_env({"NAME": "test.db.sqlite3"}, ["-help"]),
(["sqlite3", "test.db.sqlite3", "-help"], None),
)
+
+ @skipUnless(connection.vendor == "sqlite", "SQLite test")
+ def test_non_zero_exit_status_when_path_to_db_is_path(self):
+ sqlite_with_path = {
+ "ENGINE": "django.db.backends.sqlite3",
+ "NAME": Path("test.db.sqlite3"),
+ }
+ cmd_args = self.settings_to_cmd_args_env(sqlite_with_path)[0]
+
+ msg = '"sqlite3 test.db.sqlite3" returned non-zero exit status 1.'
+ with mock.patch(
+ "django.db.backends.sqlite3.client.DatabaseClient.runshell",
+ side_effect=subprocess.CalledProcessError(returncode=1, cmd=cmd_args),
+ ), self.assertRaisesMessage(CommandError, msg):
+ call_command("dbshell")