﻿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
2160	Documentation How Django knows to Update vs Insert not correct	fgutierrez AT aureal.com.pe	Jacob	"The documentation at [http://www.djangoproject.com/documentation/db_api/#id1 here] says:


{{{
- If the object's primary key attribute is set to a value that evaluates to False (such as None or the empty string), Django executes a SELECT query to determine whether a record with the given primary key already exists.
}}}


That is not true, since the code is that determines if it should check that the primary key exists is:


{{{
pk_val = self._get_pk_val()
pk_set = bool(pk_val)
record_exists = True
if pk_set:
    # Determine whether a record with the primary key already exists.
    cursor.execute(""SELECT 1 FROM %s WHERE %s=%%s LIMIT 1"" % \
                (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), [pk_val])
    # If it does already exist, do an UPDATE.
}}}



If a value that evaluates to ""False"" (as said in the documentation) is set to the pk the select is never executes and it just goes to the INSERT. Therefor the documentation should say:

{{{
- If the object's primary key attribute is NOT set to a value that evaluates to False (such as None or the empty string), Django executes a SELECT query to determine whether a record with the given primary key already exists.
}}}

And there should be a note about how to work around this for the people who uses a PK that evaluates to False such as 0, or Empty String."	defect	new	Documentation		major				Unreviewed	0	0	0	0	0	0
