Opened 13 years ago

Last modified 13 years ago

#17415 closed Bug

django.contrib.sites.management.create_default_site populates invalid data in DB — at Version 1

Reported by: niko@… Owned by: nobody
Component: contrib.sites Version: dev
Severity: Release blocker Keywords: site admin create db orm
Cc: anssi.kaariainen@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Aymeric Augustin)

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 (1)

comment:1 by Aymeric Augustin, 13 years ago

Description: modified (diff)
Type: UncategorizedBug
Note: See TracTickets for help on using tickets.
Back to Top