Opened 5 years ago
Closed 5 years ago
#30595 closed Cleanup/optimization (fixed)
sqlsequencereset should inform that no sequences found.
Reported by: | Keryn Knight | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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 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.
Change History (5)
comment:1 by , 5 years ago
Easy pickings: | set |
---|---|
Summary: | sqlsequencereset silently exits if there's nothing to do, without informing the user → sqlsequencereset should inform that no sequences found. |
Triage Stage: | Unreviewed → Accepted |
Type: | New feature → Cleanup/optimization |
Version: | 2.2 → master |
comment:2 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 5 years ago
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 sql*
commands to be coherent.
Thanks for the report. I don't think that
sqlsequencereset
should raiseCommandError
, but I agree that we can add an extra output if we don't find any sequences, e.g.