#12560: Unique validation should not check for null atuo-assigned PK
---------------------------+------------------------------------------------
 Reporter:  kmtracey       |       Owner:  nobody    
   Status:  new            |   Milestone:  1.2       
Component:  Uncategorized  |     Version:  SVN       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 Initially noted here: http://groups.google.com/group/django-
 developers/browse_thread/thread/b45c4d599ea93b74#

 The model validation unique check code is issuing an unnecessary query
 when adding new instances of models with auto-assigned PKs:

 {{{
 Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
 [GCC 4.3.2] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 (InteractiveConsole)
 >>> import django
 >>> django.get_version()
 u'1.2 alpha 1 SVN-12120'
 >>> from ttt.models import Tag
 >>> from django import forms
 >>> class TagForm(forms.ModelForm):
 ...     class Meta:
 ...         model = Tag
 ...
 >>> tf1 = TagForm({'name': 'T1'})
 >>> tf1.is_valid()
 True
 >>> from django.db import connection
 >>> connection.queries
 [{'time': '0.002', 'sql': u'SELECT (1) AS `a`, `ttt_tag`.`id`,
 `ttt_tag`.`name` FROM `ttt_tag` WHERE `ttt_tag`.`id` IS NULL LIMIT 1'}]
 >>>
 }}}

 Besides being unnecessary, that's a query that will potentially return an
 unexpected result on MySQL, see: http://groups.google.com/group/django-
 developers/browse_thread/thread/d4180b8addf5e970/

 This is similar to #12132, only for adding new instances instead of
 changing existing ones.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12560>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to