[Django] #19222: Documentation for use_for_related_fields should clarify that it doesn't work for intermediate joins

22 views
Skip to first unread message

Django

unread,
Oct 31, 2012, 7:13:00 PM10/31/12
to django-...@googlegroups.com
#19222: Documentation for use_for_related_fields should clarify that it doesn't
work for intermediate joins
-------------------------------+--------------------
Reporter: andrewbadr | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I have a custom Manager to filter out model instances with where the field
`deleted` is `True`. I'm using an ORM query that looks like
`user1.page_set.filter(membership__user=user2)`. The option
`use_for_related_fields=True` is set on the relevant manager.

My expectation is that `Membership` objects with the deleted flag set are
not included in the query. Instead, they are being included.

The documentation for `use_for_related_fields` should should specify that
it doesn't work in this case.

--
Ticket URL: <https://code.djangoproject.com/ticket/19222>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 22, 2012, 5:47:53 AM11/22/12
to django-...@googlegroups.com
#19222: Documentation for use_for_related_fields should clarify that it doesn't
work for intermediate joins
-------------------------------+--------------------------------------
Reporter: andrewbadr | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 1.4
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by mattaustin):

* status: new => closed
* needs_better_patch: => 0
* resolution: => needsinfo
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug


Comment:

Attempted to reproduce this, but require more info on model relationships.

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:1>

Django

unread,
Dec 9, 2013, 9:03:05 PM12/9/13
to django-...@googlegroups.com
#19222: Documentation for use_for_related_fields should clarify that it doesn't
work for intermediate joins
-------------------------------+--------------------------------------
Reporter: andrewbadr | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 1.4
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by jedediah):

{{{
class BagelManager(Manager):
use_for_related_fields = True

def get_query_set(self):
return super(BagelManager,
self).get_query_set().filter(deleted=False)

class Bagel(Model):
deleted = BooleanField()

objects = BagelManager()
all_bagels = Manager()

def __str__(self):
return "deleted" if self.deleted else "active"

class Customer(Model):
bagels = ManyToManyField(Bagel)
}}}

{{{
>>> Bagel.objects.create(deleted=False)
<Bagel: active>
>>> Bagel.objects.create(deleted=True)
<Bagel: deleted>
>>> Bagel.all_bagels.all()
[<Bagel: active>, <Bagel: deleted>]
>>> Bagel.objects.all()
[<Bagel: active>]
>>> Bagel.objects.filter(deleted=True)
[]
}}}
Correct so far... deleted bagel is invisible through default manager
{{{
>>> c = Customer.objects.create()
>>> c.bagels.add(*Bagel.all_bagels.all())
>>> c.bagels.all()
[<Bagel: active>]
>>> c.bagels.filter(deleted=True)
[]
}}}
Still good... deleted bagel is invisible to related fields
{{{
>>> Customer.objects.filter(bagels__deleted=True)
[<Customer: Customer object>]
}}}
Here's the problem. The query join sees the deleted bagel. I would expect
queries through relations to see the same data as the relations
themselves.

This should either be fixed or documented as a known limitation.

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:2>

Django

unread,
Dec 9, 2013, 9:03:40 PM12/9/13
to django-...@googlegroups.com
#19222: Documentation for use_for_related_fields should clarify that it doesn't
work for intermediate joins
-------------------------------+--------------------------------------
Reporter: andrewbadr | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by jedediah):

* status: closed => new
* resolution: needsinfo =>


--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:3>

Django

unread,
Apr 28, 2014, 8:00:34 PM4/28/14
to django-...@googlegroups.com
#19222: Documentation for use_for_related_fields should clarify that it doesn't
work for intermediate joins
--------------------------------------+------------------------------------
Reporter: andrewbadr | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

I don't think this a behavior that's going to change, so documentation
seems like the way to go. If you'd like to write a patch, I'll be happy to
review it.

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:4>

Django

unread,
May 9, 2016, 8:28:09 PM5/9/16
to django-...@googlegroups.com
#19222: Documentation for use_for_related_fields should clarify that it doesn't
work for intermediate joins
-------------------------------------+-------------------------------------
Reporter: andrewbadr | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
use_for_related_fields |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* keywords: => use_for_related_fields


--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:5>

Django

unread,
May 16, 2016, 2:18:56 PM5/16/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
--------------------------------------+------------------------------------
Reporter: andrewbadr | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by loic):

* keywords: use_for_related_fields =>
* version: 1.4 => master


Old description:

> I have a custom Manager to filter out model instances with where the
> field `deleted` is `True`. I'm using an ORM query that looks like
> `user1.page_set.filter(membership__user=user2)`. The option
> `use_for_related_fields=True` is set on the relevant manager.
>
> My expectation is that `Membership` objects with the deleted flag set are
> not included in the query. Instead, they are being included.
>
> The documentation for `use_for_related_fields` should should specify that
> it doesn't work in this case.

New description:

I have a custom Manager to filter out model instances with where the field
`deleted` is `True`. I'm using an ORM query that looks like
`user1.page_set.filter(membership__user=user2)`.

My expectation is that `Membership` objects with the deleted flag set are


not included in the query. Instead, they are being included.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:6>

Django

unread,
Jun 2, 2016, 5:55:45 PM6/2/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
--------------------------------------+------------------------------------
Reporter: andrewbadr | Owner: Hwesta
Type: Cleanup/optimization | Status: assigned

Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Hwesta):

* status: new => assigned
* owner: nobody => Hwesta
* easy: 0 => 1
* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:7>

Django

unread,
Jul 11, 2016, 4:11:04 PM7/11/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
--------------------------------------+------------------------------------
Reporter: andrewbadr | Owner: Hwesta
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* needs_docs: 1 => 0


Comment:

[https://github.com/django/django/pull/6902 PR] with comments for
improvement.

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:8>

Django

unread,
Jul 11, 2016, 4:14:26 PM7/11/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
--------------------------------------+------------------------------------
Reporter: andrewbadr | Owner:
Type: Cleanup/optimization | Status: new

Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Hwesta):

* owner: Hwesta =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:9>

Django

unread,
Jul 12, 2016, 11:05:41 AM7/12/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
--------------------------------------+------------------------------------
Reporter: andrewbadr | Owner:
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:10>

Django

unread,
Aug 8, 2016, 10:06:18 AM8/8/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
-------------------------------------+-------------------------------------
Reporter: andrewbadr | Owner:
Type: | yanikkoval
Cleanup/optimization | Status: assigned

Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by yanikkoval):

* status: new => assigned

* owner: => yanikkoval


--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:11>

Django

unread,
Aug 8, 2016, 10:09:28 AM8/8/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
-------------------------------------+-------------------------------------
Reporter: andrewbadr | Owner:
Type: | yanikkoval
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

yanikkoval, not sure why you assigned yourself to the ticket. In case you
didn't see it, we have a patch awaiting review linked in comment:8.

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:12>

Django

unread,
Aug 8, 2016, 10:12:59 AM8/8/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
-------------------------------------+-------------------------------------
Reporter: andrewbadr | Owner:
Type: | yanikkoval
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by yanikkoval):

Sorry, didn't notice.

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:13>

Django

unread,
Aug 12, 2016, 7:09:02 PM8/12/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
-------------------------------------+-------------------------------------
Reporter: andrewbadr | Owner:
Type: | yanikkoval
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* easy: 1 => 0


Comment:

I felt the existing proposal is more verbose than needed, so I created an
alternate [https://github.com/django/django/pull/7074 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:14>

Django

unread,
Aug 16, 2016, 1:13:23 PM8/16/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
-------------------------------------+-------------------------------------
Reporter: andrewbadr | Owner:
Type: | yanikkoval
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"8fb53c50ce1c759c740960c9e1cef3cef39cabc5" 8fb53c50]:
{{{
#!CommitTicketReference repository=""
revision="8fb53c50ce1c759c740960c9e1cef3cef39cabc5"
Fixed #19222 -- Documented that default managers aren't used for related
queries.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:15>

Django

unread,
Aug 16, 2016, 1:13:31 PM8/16/16
to django-...@googlegroups.com
#19222: Clarify that custom managers don't apply to intermediate joins
-------------------------------------+-------------------------------------
Reporter: andrewbadr | Owner:
Type: | yanikkoval
Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"8df2da36379cfce0efc7f2da96fc076ed221dc0a" 8df2da3]:
{{{
#!CommitTicketReference repository=""
revision="8df2da36379cfce0efc7f2da96fc076ed221dc0a"
[1.10.x] Fixed #19222 -- Documented that default managers aren't used for
related queries.

Backport of 8fb53c50ce1c759c740960c9e1cef3cef39cabc5 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:16>

Reply all
Reply to author
Forward
0 new messages