﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17415	django.contrib.sites.management.create_default_site populates invalid data in DB	niko@…	nobody	"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.
"	Bug	closed	contrib.sites	dev	Release blocker	fixed	site admin create db orm	anssi.kaariainen@…	Accepted	1	0	0	0	0	0
