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 Mariusz Felisiak, 5 years ago

Easy pickings: set
Summary: sqlsequencereset silently exits if there's nothing to do, without informing the usersqlsequencereset should inform that no sequences found.
Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization
Version: 2.2master

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.

if not statements and self.verbosity >= 1:
    self.stdout.write('No sequences found.')

comment:2 by Hasan Ramezani, 5 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:3 by Simon Charette, 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.

Last edited 5 years ago by Simon Charette (previous) (diff)

comment:4 by Hasan Ramezani, 5 years ago

Has patch: set
Last edited 5 years ago by Mariusz Felisiak (previous) (diff)

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 5d03f2b:

Fixed #30595 -- Added error message when no objects found to sql* management commands.

Note: See TracTickets for help on using tickets.
Back to Top