[Django] #29501: Add support for ./manage.py dbshell -c SQL

25 views
Skip to first unread message

Django

unread,
Jun 17, 2018, 3:32:50 PM6/17/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem | Owner: nobody
Skoretskiy |
Type: New | Status: new
feature |
Component: Core | Version: 2.0
(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 |
-------------------------------------+-------------------------------------
At the moment you cannot run specific SQL directly with `dbshell`:

{{{
./manage.py dbshell -c "select * from auth_group"
}}}

You have to use pipes, that are not always convenient:

{{{
echo "select * from auth_group" | ./manage.py dbshell
}}}

If we add `-c` argument, it would be in sync with `shell` command, where
you could provide commands already.

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

Django

unread,
Jun 18, 2018, 6:02:18 AM6/18/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* version: 2.0 => master
* stage: Unreviewed => Accepted


Comment:

This seems reasonable, at first glance at least. The trick will be to pass
the command to each of the backend clients correctly, but there's no
reason that's not possible right? Accepting on that basis. A PR is very
welcome.

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

Django

unread,
Jun 18, 2018, 12:57:06 PM6/18/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Zijian He
Type: New feature | Status: assigned

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Zijian He):

* owner: nobody => Zijian He
* cc: Zijian He (added)
* status: new => assigned


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

Django

unread,
Jun 19, 2018, 2:07:50 PM6/19/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: cedric05

Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by cedric05):

* owner: Zijian He => cedric05


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

Django

unread,
Jun 20, 2018, 1:13:33 AM6/20/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: (none)

Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shiva Prasanth):

* status: assigned => new
* owner: Shiva Prasanth => (none)


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

Django

unread,
Jun 20, 2018, 1:52:43 AM6/20/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: (none)
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Artem Skoretskiy):

It should be easy to implement since we don’t need to use database-
specific backend

Something like that:

{{{
from django.db import connection

if command:
cursor = connection.cursor()
cursor.execute(command)
# show `cursor.fetchall()` result
}}}

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

Django

unread,
Jun 29, 2018, 7:01:10 AM6/29/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: (none)
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Volodymyr Dmytriiev):

any progress on this one? Is the previously suggested approach good
enough? If so, I'd love to give a try?

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

Django

unread,
Jun 29, 2018, 9:47:42 AM6/29/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: (none)
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Artem Skoretskiy):

No progress AKAIK.

Maybe it would be easier to call database-specific CLI tool with right
parameters than run cursor.

Pros:
* No need to care about printing results (user could execute SELECT)
* Could run commands that are unique for the CLI (e.g. \dt to show tables
in psql)

Cons:
* Each backend would need its own command to run (but we already have
dbshell, so we know name of binary; just need a parameter to execute a
query).
* Each backend would show results in its own format, so you cannot e. g.
save result as cab file)

Another completely different approach would be to pass all command line
arguments provided to dbshell, e.g. after “—“ divider to database CLI app.
For example:
{{{
./manage.py dbshell — -c “select * from auth_user”
}}}

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

Django

unread,
Jul 2, 2018, 6:58:37 AM7/2/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: (none)
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adam (Chainz) Johnson):

I don't think opening a cursor is the right way. My mental model of
dbshell is that it always passes through to the underlying tool, which can
have subtle implications on even what SQL/commands are accepted.

I am actually most in favour of passing all arguments through after a `--`
divider as that is the most flexible.

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:8>

Django

unread,
Jul 2, 2018, 11:10:24 AM7/2/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner:
| introquest

Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by introquest):

* status: new => assigned

* owner: (none) => introquest


--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:9>

Django

unread,
Jul 16, 2018, 2:44:59 AM7/16/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner:
| introquest
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

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

* needs_docs: 0 => 1
* has_patch: 0 => 1
* needs_tests: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

https://github.com/django/django/pull/10186

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:10>

Django

unread,
Jul 16, 2018, 2:19:18 PM7/16/18
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner:
| introquest
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Ready for checkin => Accepted


Comment:

"Ready for checkin" is set by a patch reviewer. And the patch isn't ready
for review without tests and documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:11>

Django

unread,
Sep 27, 2019, 3:30:57 PM9/27/19
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner:
| introquest
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by David Vaz):

So the PR is closed due to missing Tests and Documentation. Does anybody
care that I take this?
I could make a PR based on the original one and add tests and docs

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:12>

Django

unread,
Sep 27, 2019, 4:15:24 PM9/27/19
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner:
| introquest
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

Absolutely, feel free to work on issues obviously stalled. Just credit
original patch writers if appropriate.

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:13>

Django

unread,
Feb 29, 2020, 3:14:16 AM2/29/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson

Type: New feature | Status: assigned
Component: Core (Management | Version: master
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 Adam (Chainz) Johnson):

* owner: introquest => Adam (Chainz) Johnson
* needs_docs: 1 => 0
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:14>

Django

unread,
Mar 20, 2020, 1:25:27 AM3/20/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:15>

Django

unread,
Mar 20, 2020, 10:42:34 AM3/20/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: assigned
Component: Core (Management | Version: master
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 Adam (Chainz) Johnson):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:16>

Django

unread,
Apr 14, 2020, 7:27:45 AM4/14/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: assigned
Component: Core (Management | Version: master
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 felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:17>

Django

unread,
Apr 14, 2020, 2:42:53 PM4/14/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: closed

Component: Core (Management | Version: master
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 Adam Johnson <me@…>):

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


Comment:

In [changeset:"5b884d45ac5b76234eca614d90c83b347294c332" 5b884d45]:
{{{
#!CommitTicketReference repository=""
revision="5b884d45ac5b76234eca614d90c83b347294c332"
Fixed #29501 -- Allowed dbshell to pass options to underlying tool.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:22>

Django

unread,
Apr 14, 2020, 2:42:53 PM4/14/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: assigned

Component: Core (Management | Version: master
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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"6cad911674dc067ffab44eea4f5c8170fa0a89b1" 6cad9116]:
{{{
#!CommitTicketReference repository=""
revision="6cad911674dc067ffab44eea4f5c8170fa0a89b1"
Refs #29501 -- Simplified BaseCommand.run_from_argv() a bit.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:20>

Django

unread,
Apr 14, 2020, 2:42:53 PM4/14/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: assigned
Component: Core (Management | Version: master
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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"8189976663eb160bfd4b2ae44fd5250da1089744" 8189976]:
{{{
#!CommitTicketReference repository=""
revision="8189976663eb160bfd4b2ae44fd5250da1089744"
Refs #29501 -- Added test for missing dbshell executable.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:18>

Django

unread,
Apr 14, 2020, 2:42:53 PM4/14/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: assigned
Component: Core (Management | Version: master
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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"8bd9000a7db3dcf14b003e8ef18137ea1296c07b" 8bd9000]:
{{{
#!CommitTicketReference repository=""
revision="8bd9000a7db3dcf14b003e8ef18137ea1296c07b"
Refs #29501 -- Made dbshell catch more specific FileNotFoundError.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:19>

Django

unread,
Apr 14, 2020, 2:42:54 PM4/14/20
to django-...@googlegroups.com
#29501: Add support for ./manage.py dbshell -c SQL
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: Adam
| (Chainz) Johnson
Type: New feature | Status: assigned
Component: Core (Management | Version: master
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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"8e8c3f964e23e669fc563a74750e51abba4c2e3a" 8e8c3f96]:
{{{
#!CommitTicketReference repository=""
revision="8e8c3f964e23e669fc563a74750e51abba4c2e3a"
Refs #29501 -- Allowed customizing exit status for management commands.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:21>

Reply all
Reply to author
Forward
0 new messages