Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #32061 -- Unified DatabaseClient.runshell() in db backends.
- Loading branch information
Showing
16 changed files
with
273 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import subprocess | ||
|
||
from django.db.backends.base.client import BaseDatabaseClient | ||
|
||
|
||
class DatabaseClient(BaseDatabaseClient): | ||
executable_name = 'sqlite3' | ||
|
||
def runshell(self, parameters): | ||
# TODO: Remove str() when dropping support for PY37. | ||
# args parameter accepts path-like objects on Windows since Python 3.8. | ||
args = [self.executable_name, | ||
str(self.connection.settings_dict['NAME'])] | ||
args.extend(parameters) | ||
subprocess.run(args, check=True) | ||
@classmethod | ||
def settings_to_cmd_args_env(cls, settings_dict, parameters): | ||
args = [ | ||
cls.executable_name, | ||
# TODO: Remove str() when dropping support for PY37. args | ||
# parameter accepts path-like objects on Windows since Python 3.8. | ||
str(settings_dict['NAME']), | ||
*parameters, | ||
] | ||
return args, None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.db import connection | ||
from django.db.backends.base.client import BaseDatabaseClient | ||
from django.test import SimpleTestCase | ||
|
||
|
||
class SimpleDatabaseClientTests(SimpleTestCase): | ||
def setUp(self): | ||
self.client = BaseDatabaseClient(connection=connection) | ||
|
||
def test_settings_to_cmd_args_env(self): | ||
msg = ( | ||
'subclasses of BaseDatabaseClient must provide a ' | ||
'settings_to_cmd_args_env() method or override a runshell().' | ||
) | ||
with self.assertRaisesMessage(NotImplementedError, msg): | ||
self.client.settings_to_cmd_args_env(None, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.