#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)
Change History (7)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
| milestone: | → 1.2 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 16 years ago
Almost definitely just a matter of passing auto=True (or whatever the kwarg is named) to cache.get_models()
by , 16 years ago
| Attachment: | 13248_sqlsequencereset.diff added |
|---|
sets include_auto_created to True for sqlsequencereset
comment:4 by , 16 years ago
| Has patch: | set |
|---|---|
| Needs tests: | set |
| Owner: | changed from to |
| Status: | new → 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 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Database backend is
postgresql_psycopg2.