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.
* 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>
* status: new => assigned
* owner: nobody => Hasan Ramezani
--
Ticket URL: <https://code.djangoproject.com/ticket/30595#comment:2>
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>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30595#comment:4>
* 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>