#12870: ORM bug with using exclude in conjunction with Q objects
---------------------------------------------------+------------------------
          Reporter:  subsume                       |         Owner:  nobody   
            Status:  new                           |     Milestone:  1.2      
         Component:  Database layer (models, ORM)  |       Version:  1.1      
        Resolution:                                |      Keywords:  exclude Q
             Stage:  Accepted                      |     Has_patch:  0        
        Needs_docs:  0                             |   Needs_tests:  0        
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by subsume):

 I verified that this bug still exists in latest svn. updated console:

 {{{

 >>>
 
Deck.objects.filter(user__username='nammertime').exclude(Q(category='pro')|Q(category='precon')).query.get_compiler('default').as_sql()
 ('SELECT `deck_deck`.`id`, `deck_deck`.`format_id`, `deck_deck`.`name`,
 `deck_deck`.`slug`, `deck_deck`.`user_id`, `deck_deck`.`description`,
 `deck_deck`.`profile_cardinality`, `deck_deck`.`date_added`,
 `deck_deck`.`date_updated`, `deck_deck`.`date_refreshed`,
 `deck_deck`.`is_private`, `deck_deck`.`category`,
 `deck_deck`.`preconstructed_set_id`, `deck_deck`.`cost`,
 `deck_deck`.`view_count_cache`, `deck_deck`.`comment_count_cache`,
 `deck_deck`.`data_generated`, `deck_deck`.`image_token`,
 `deck_deck`.`similar_due`, `deck_deck`.`rating_votes`,
 `deck_deck`.`rating_score` FROM `deck_deck` INNER JOIN `auth_user` ON
 (`deck_deck`.`user_id` = `auth_user`.`id`) WHERE (`auth_user`.`username` =
 %s  AND NOT ((`deck_deck`.`category` = %s  OR `deck_deck`.`category` = %s
 )))', ('nammertime', 'pro', 'precon'))

 >>>
 
Deck.objects.filter(user__username='nammertime').exclude(category='pro').exclude(category='precon').query.get_compiler('default').as_sql()
 ('SELECT `deck_deck`.`id`, `deck_deck`.`format_id`, `deck_deck`.`name`,
 `deck_deck`.`slug`, `deck_deck`.`user_id`, `deck_deck`.`description`,
 `deck_deck`.`profile_cardinality`, `deck_deck`.`date_added`,
 `deck_deck`.`date_updated`, `deck_deck`.`date_refreshed`,
 `deck_deck`.`is_private`, `deck_deck`.`category`,
 `deck_deck`.`preconstructed_set_id`, `deck_deck`.`cost`,
 `deck_deck`.`view_count_cache`, `deck_deck`.`comment_count_cache`,
 `deck_deck`.`data_generated`, `deck_deck`.`image_token`,
 `deck_deck`.`similar_due`, `deck_deck`.`rating_votes`,
 `deck_deck`.`rating_score` FROM `deck_deck` INNER JOIN `auth_user` ON
 (`deck_deck`.`user_id` = `auth_user`.`id`) WHERE (`auth_user`.`username` =
 %s  AND NOT (`deck_deck`.`category` = %s  AND NOT (`deck_deck`.`category`
 IS NULL)) AND NOT (`deck_deck`.`category` = %s  AND NOT
 (`deck_deck`.`category` IS NULL)))', ('nammertime', 'pro', 'precon'))
 >>>

 }}}

 I realize that the tests you can seemed to come up clean, however, there
 is still some burden to explain the extraneous JOINS. Obviously the test
 case isn't close enough to the actual problem. Indeed, the fact that such
 a basic bug can live this long must mean there is a nuance missing. If
 filter(Q()|Q()) was broken, it would have been found in minutes.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12870#comment:7>
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