Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#13248 closed (fixed)

manage.py sqlsequencereset misses m2m tables

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

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 Gabriel Hurley 14 years ago.
sets include_auto_created to True for sqlsequencereset

Download all attachments as: .zip

Change History (7)

comment:1 by Andrey Golovizin, 14 years ago

Database backend is postgresql_psycopg2.

comment:2 by Ramiro Morales, 14 years ago

milestone: 1.2
Triage Stage: UnreviewedAccepted

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 by Alex Gaynor, 14 years ago

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

by Gabriel Hurley, 14 years ago

Attachment: 13248_sqlsequencereset.diff added

sets include_auto_created to True for sqlsequencereset

comment:4 by Gabriel Hurley, 14 years ago

Has patch: set
Needs tests: set
Owner: changed from nobody to Gabriel Hurley
Status: newassigned

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 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: assignedclosed

(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 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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