[Django] #30595: sqlsequencereset silently exits if there's nothing to do, without informing the user

9 views
Skip to first unread message

Django

unread,
Jun 26, 2019, 5:13:05 AM6/26/19
to django-...@googlegroups.com
#30595: sqlsequencereset silently exits if there's nothing to do, without informing
the user
-------------------------------------+-------------------------------------
Reporter: Keryn | Owner: nobody
Knight |
Type: New | Status: new
feature |
Component: Core | Version: 2.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 |
-------------------------------------+-------------------------------------
This just came up on IRC, because someone was expecting `sqlsequencereset`
to provide resets for the auto-increment values for an SQLite table.

Running `python manage.py sqlsequencereset <myapp>` provides no output if
there are no results returned by `connection.ops.sequence_reset_sql` (see
[https://github.com/django/django/blob/26d16c07fdc4a297daca554afa6375c70d6d82a9/django/core/management/commands/sqlsequencereset.py#L23
here])
So the user has no idea if it failed, succeeded, or they got the
invocation wrong (assuming they're not familiar enough with Django to know
that invoking it wrong will raise a `CommandError`).

I'd suggest it should avoid ambiguity, so if `len(statements) == 0` it
should raise `CommandError` and say there's nothing to do. Bonus points if
it also sniffs the connection backend to know if there is anything it
**could** do, and if there's not, report that `sqlsequencereset` isn't
necessary/available for that backend.

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

Django

unread,
Jun 26, 2019, 5:31:29 AM6/26/19
to django-...@googlegroups.com
#30595: sqlsequencereset should inform that no sequences found.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: nobody
Type: | Status: new
Cleanup/optimization |
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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Unreviewed => Accepted
* version: 2.2 => master
* type: New feature => Cleanup/optimization
* easy: 0 => 1


Comment:

Thanks for the report. I don't think that `sqlsequencereset` should raise
`CommandError`, but I agree that we can add an extra output if we don't
find any sequences, e.g.

{{{#!python
if not statements and self.verbosity >= 1:
self.stdout.write('No sequences found.')
}}}

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

Django

unread,
Jun 29, 2019, 12:08:26 PM6/29/19
to django-...@googlegroups.com
#30595: sqlsequencereset should inform that no sequences found.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | 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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* status: new => assigned
* owner: nobody => Hasan Ramezani


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

Django

unread,
Jun 29, 2019, 12:27:07 PM6/29/19
to django-...@googlegroups.com
#30595: sqlsequencereset should inform that no sequences found.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | 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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

One problem I foresee with outputting a message when no sequences are
found is that it could break scripts piping the output into a SQL shell or
simply expecting STDOUT to be valid SQL. I guess we could output an SQL
comment of the form `-- No sequences found` or use STDERR instead?

Also I don't see why `sqlsequencereset` is special with regards to other
`sql*` commands that also have the same behavior; it should either not be
changed or changed for all commands `sql*` commands to be coherent.

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

Django

unread,
Jun 29, 2019, 8:25:48 PM6/29/19
to django-...@googlegroups.com
#30595: sqlsequencereset should inform that no sequences found.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | 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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* has_patch: 0 => 1


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

Django

unread,
Jul 1, 2019, 8:21:40 AM7/1/19
to django-...@googlegroups.com
#30595: sqlsequencereset should inform that no sequences found.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed

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

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"5d03f2bc01fc08f57558cdd3b4fc08e6b379dad7" 5d03f2b]:
{{{
#!CommitTicketReference repository=""
revision="5d03f2bc01fc08f57558cdd3b4fc08e6b379dad7"
Fixed #30595 -- Added error message when no objects found to sql*
management commands.
}}}

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

Reply all
Reply to author
Forward
0 new messages