#14029: not operator on F objects silently fails
------------------------------------------+---------------------------------
 Reporter:  ramiro                        |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.2       
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 [On behalf of Matías Bellone aka toote that got his submission rejected as
 SPAM]

 Trying to make a toggle action in the admin on a !BooleanField lead me to
 very simple and straightforward code inside the !ModelAdmin subclass.
 Problem is that it didn't work and no error was presented whatsoever. Even
 worse, the update actually executes something that modifies the queryset
 but I haven't found a way to identify how to get the query executed.

 The model can be just as simple as:


 {{{
 from django.db.models import Model, BooleanField

 class TestModel(Model):
     field1 = BooleanField()
 }}}

 Testing the "action" in an interactive shell has the same results:

 {{{
 $ ./manage.py shell
 Python 2.6.5+ (release26-maint, Jul  6 2010, 12:58:20)
 [GCC 4.4.4] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 (InteractiveConsole)
 >>> from models import TestModel
 >>> a = TestModel.objects.all()
 >>> for instance in a:
 ...     print instance.field1
 ...
 True
 True
 >>> from django.db.models import F
 >>> a = TestModel.objects.all()
 >>> # to return to having a non-executed queryset
 >>> a.update(field1=not F('field1'))
 2
 >>> a = TestModel.objects.all()
 >>> for instance in a:
 ...     print instance.field1
 ...
 True
 True
 }}}

 Further tests with the debug_toolbar shows that no matter what the
 original values of field1 is the update will set it to true (tested on
 querysets with 1 and 2 instances with all possible combinations of field1
 values).

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14029>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to