Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13248 closed (fixed)

manage.py sqlsequencereset misses m2m tables

Reported by: EroSennin Owned by: gabrielhurley
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

Sequence reset code not generated for tables that are implicitly created for m2m fields.

Example models:

class User(models.Model):
    pass

class Group(models.Model):
    users = models.ManyToManyField(User)

The correct result of ./manage.py sqlsequencereset should be:

BEGIN;
SELECT setval('"example_user_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "example_user";
SELECT setval('"example_group_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "example_group";
SELECT setval('"example_group_users_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "example_group_users";
COMMIT;

Actual (incorrect) result:

BEGIN;
SELECT setval('"example_user_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "example_user";
SELECT setval('"example_group_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "example_group";
COMMIT;

Sequence example_group_users_id_seq is ignored here.

Attachments (1)

13248_sqlsequencereset.diff (671 bytes) - added by gabrielhurley 4 years ago.
sets include_auto_created to True for sqlsequencereset

Download all attachments as: .zip

Change History (7)

comment:1 Changed 4 years ago by EroSennin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Database backend is postgresql_psycopg2.

comment:2 Changed 4 years ago by ramiro

  • milestone set to 1.2
  • Triage Stage changed from Unreviewed to Accepted

Bisection between 1.1 (r11366) and current trunk tip (r12889) shows this was introduced in r11710. Accepting and setting target to 1.2 as this is a regression.

comment:3 Changed 4 years ago by Alex

Almost definitely just a matter of passing auto=True (or whatever the kwarg is named) to cache.get_models()

Changed 4 years ago by gabrielhurley

sets include_auto_created to True for sqlsequencereset

comment:4 Changed 4 years ago by gabrielhurley

  • Has patch set
  • Needs tests set
  • Owner changed from nobody to gabrielhurley
  • Status changed from new to assigned

I've attached a patch which causes the auto-created models to be reset as they should, but for the life of me I can't figure out how to write a regression test for this...

If anyone has a bright idea on how to test without comparing SQL line-for-line (which will vary by backend) let me know.

comment:5 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [12903]) Fixed #13248 -- Corrected the output of sqlsequencereset after the m2m changes. Thanks to EroSennin? for the report, and Gabriel Hurley for the fix.

comment:6 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.