django.contrib.sites.management.create_default_site populates invalid data in DB
|Reported by:||niko@…||Owned by:||nobody|
|Severity:||Release blocker||Keywords:||site admin create db orm|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by aaugustin)
With a PostgeSQL backend, in trunk revision 1.4 pre-alpha SVN-17189
During syncdb, in the function django.contrib.sites.management.create_default_site,
the default Site 'exemple.com' is created.
But for some reason, the postgres sequence 'django_site_id_seq' is then in an incorrect state.
The last value = 1 (this is ok)
but the flag "Will increment last value before returning next value (is_called)" = No
And this parameter is different in any other table generated by the ORM.
Name Start value Last value Increment by Max value Min value Cache value Log count Can cycle? Will increment last value before returning next value (is_called)? django_site_id_seq 1 1 1 9223372036854775807 1 1 1 No No
What happens then?
If you go to the admin and want to add a second Site, when u save, you get the exception:
Exception Type: IntegrityError duplicate key value violates unique constraint "django_site_pkey" DETAIL: Key (id)=(1) already exists.
At this point, the add in the DB failed, but the ORM just changed the flag in the Sequence django_site_id_seq.is_called = Yes
This will allow the next attempt to save this second Site (reload the page and resend the POST data, by exemple) to succeed.
How to reproduce the bug at this stage:
in the postgresql, delete the table django_site, run manage.py syncdb, this will create a new table and repopulate the exemple.com default Site, and the buggy is_called tag on the django_site_id_seq sequence.
Then, i dont know why the function django.contrib.sites.management.create_default_site is putting this tag to False.
I havent tested on mysql, andi dont know how increment index is working there.
Change History (15)
comment:1 Changed 4 years ago by aaugustin
- Description modified (diff)
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Type changed from Uncategorized to Bug
Changed 4 years ago by aaugustin
comment:5 Changed 4 years ago by aaugustin
- Component changed from contrib.sites to Database layer (models, ORM)
- Severity changed from Release blocker to Normal
- Summary changed from django.contrib.sites.management.create_default_site populates invalid data in DB to Creating an object with an explicit primary key value causes the next creation to fail under PostgreSQL
comment:8 Changed 4 years ago by kmtracey
- Component changed from Database layer (models, ORM) to contrib.sites
Changed 4 years ago by akaariai
comment:11 Changed 3 years ago by aaugustin
- Summary changed from Creating an object with an explicit primary key value causes the next creation to fail under PostgreSQL to django.contrib.sites.management.create_default_site populates invalid data in DB
comment:12 Changed 3 years ago by aaugustin
- Resolution set to fixed
- Status changed from new to closed