Opened 8 years ago

Closed 7 years ago

#4464 closed (fixed)

Chaining filters on ManyToManyFields broken?

Reported by: ml_django25@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: manytomany, manytomanyfield, qs-rf-fixed
Cc: b-django@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The last part of this fails (with MySql 5):

from django.db import models

class Category(models.Model):
    name=models.CharField(maxlength=40)

class Thing(models.Model):
    """
    >>> cat1 = Category.objects.create(name="cat2")
    >>> cat1.save()
    >>> cat2 = Category.objects.create(name="cat2")
    >>> cat2.save()
    >>> my_thing = Thing.objects.create(name="My thing")
    >>> my_thing.save()
    >>> my_thing.categories = [cat1, cat2]
    >>> Thing.objects.filter(categories=cat1)
    [<Thing: My thing>]
    >>> Thing.objects.filter(categories=cat2)
    [<Thing: My thing>]
    >>> Thing.objects.filter(categories=cat1).filter(categories=cat2)
    [<Thing: My thing>]
    """
    name=models.CharField(maxlength=40)
    categories = models.ManyToManyField(Category)
    def __str__(self):
        return self.name

Am I right in thinking that ought to pass?

Change History (4)

comment:1 Changed 8 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from adrian to mtredinnick
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This is a dupe of something (I thought), but I can't find. It should work. I'm working on it.

comment:2 Changed 8 years ago by anonymous

  • Cc b-django@… added

comment:3 Changed 7 years ago by mtredinnick

  • Keywords qs-rf-fixed added

comment:4 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

Note: See TracTickets for help on using tickets.
Back to Top