#12870: ORM bug with using exclude in conjunction with Q objects ------------------------------------------+--------------------------------- Reporter: subsume | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: 1.1 Keywords: exclude Q | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- Here's a shell session which illustrates the problem.
>>> from tapped.deck.models import Deck >>> from django.db.models import Q >>> Deck.objects.filter(user__username='nammertime') [<Deck: Walled Out (Legacy) *Private*>, <Deck: Reign of Fire (Legacy) *Private*>, <Deck: Wake of the Cataclysm (Legacy) *Private*>, <Deck: WMDs (Extended) *Private*>, <Deck: Chernabog (Legacy) *Private*>, <Deck: Dark Alliance (Legacy) *Private*>, <Deck: Elf Horde (Legacy) *Private*>, <Deck: Natural Selection *Private*>, <Deck: Sliver Rush (Legacy) *Private*>, <Deck: Rath's Last Conscripts (Legacy) *Private*>, <Deck: Furious Assault (Legacy) *Private*>, <Deck: Urza's Venom (Legacy) *Private*>, <Deck: Sapling EDH (Legacy) *Private*>, <Deck: Ashling EDH (Legacy) *Private*>] >>> Deck.objects.filter(user__username='nammertime').count() 14 >>> Deck.objects.filter(user__username='nammertime').exclude(category='pro').exclude(category='precon') [<Deck: Walled Out (Legacy) *Private*>, <Deck: Reign of Fire (Legacy) *Private*>, <Deck: Wake of the Cataclysm (Legacy) *Private*>, <Deck: WMDs (Extended) *Private*>, <Deck: Chernabog (Legacy) *Private*>, <Deck: Dark Alliance (Legacy) *Private*>, <Deck: Elf Horde (Legacy) *Private*>, <Deck: Natural Selection *Private*>, <Deck: Sliver Rush (Legacy) *Private*>, <Deck: Rath's Last Conscripts (Legacy) *Private*>, <Deck: Furious Assault (Legacy) *Private*>, <Deck: Urza's Venom (Legacy) *Private*>, <Deck: Sapling EDH (Legacy) *Private*>, <Deck: Ashling EDH (Legacy) *Private*>] >>> Deck.objects.filter(user__username='nammertime').exclude(category='pro').exclude(category='precon').count() 14 >>> Deck.objects.filter(user__username='nammertime').exclude(Q(category='pro')|Q(category='precon')) >>> Deck.objects.filter(user__username='nammertime').exclude(Q(category='pro')|Q(category='precon')) [] >>> Deck.objects.filter(user__username='nammertime').exclude(Q(category='pro')|Q(category='precon')).count() 0 >>> Deck.objects.filter(user__username='nammertime').filter(category='pro') [] >>> Deck.objects.filter(user__username='nammertime').filter(category='precon') [] >>> Deck.objects.filter(user__username='nammertime').exclude(Q(category='pro')|Q(category='precon')).query.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.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')) -- Ticket URL: <http://code.djangoproject.com/ticket/12870> 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.