Re: [Django] #10913: Default related_name is broken

10 views
Skip to first unread message

Django

unread,
Jun 15, 2011, 12:41:46 AM6/15/11
to django-...@googlegroups.com
#10913: Default related_name is broken
-------------------------------------+-------------------------------------
Reporter: neithere | Owner: nobody
Type: | Status: reopened
Uncategorized | Component: Database layer
Milestone: | (models, ORM)
Version: SVN | Severity: Normal
Resolution: | Keywords: orm, related_name,
Triage Stage: | Has patch: 0
Unreviewed | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by Greg Brown <greg@…>):

* status: closed => reopened
* severity: => Normal
* cc: greg@… (added)
* resolution: invalid =>
* easy: => 0
* ui_ux: => 0
* type: => Uncategorized


Comment:

I think the OP is correct here, at least in that the ORM is inconsistent.
The docs state that the default related name is {{{FOO_set}}}, and while
this is true when accessing the manager, the OP gets differing behaviour
when explicitly setting {{{related_name='book_set'}}} to the default when
filtering (as do I). To spell it out again, the following will work:

{{{
class Event(models.Model):
...

class Image(models.Model):
event = models.ForeignKey(Event, related_name='image_set')

>>> Event.objects.filter(image_set__isnull=True)
}}}

Whereas this will throw a {{{FieldError}}}:

{{{
class Event(models.Model):
...

class Image(models.Model):
event = models.ForeignKey(Event)

>>> Event.objects.filter(image_set__isnull=True)
}}}

This ticket does not indicate "a misunderstanding about Django, how it
works, and how to use it"; rather it points out a gotcha that needs to be
fixed, or at the very least properly documented.

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

Django

unread,
Jun 15, 2011, 12:41:47 AM6/15/11
to django-...@googlegroups.com

Django

unread,
Jun 15, 2011, 12:42:20 AM6/15/11
to django-...@googlegroups.com
#10913: Default related_name is broken
-------------------------------------+-------------------------------------
Reporter: neithere | Owner: nobody
Type: | Status: reopened
Uncategorized | Component: Database layer
Milestone: | (models, ORM)
Version: SVN | Severity: Normal
Resolution: | Keywords: orm, related_name,
Triage Stage: | Has patch: 0
Unreviewed | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by Greg Brown <greg@…>):

* status: closed => reopened
* severity: => Normal

* type: => Uncategorized

* easy: => 0
* ui_ux: => 0

* resolution: invalid =>

Django

unread,
Jun 15, 2011, 12:52:55 AM6/15/11
to django-...@googlegroups.com
#10913: Default related_name is broken
-------------------------------------+-------------------------------------
Reporter: neithere | Owner: nobody
Type: | Status: reopened
Uncategorized | Component: Database layer
Milestone: | (models, ORM)
Version: SVN | Severity: Normal
Resolution: | Keywords: orm, related_name,
Triage Stage: | Has patch: 0
Unreviewed | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------

Comment (by gregplaysguitar):

Sorry about that, I was getting gateway timeouts so hit refresh a couple
of times.

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

Django

unread,
Jun 15, 2011, 12:54:17 AM6/15/11
to django-...@googlegroups.com
#10913: Default related_name is broken
-------------------------------------+-------------------------------------
Reporter: neithere | Owner: nobody
Type: | Status: reopened
Cleanup/optimization | Component: Documentation
Milestone: | Severity: Normal
Version: SVN | Keywords: orm, related_name,
Resolution: | Has patch: 0
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 1 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by russellm):

* needs_docs: 0 => 1
* type: Uncategorized => Cleanup/optimization
* component: Database layer (models, ORM) => Documentation
* stage: Unreviewed => Accepted


Comment:

The code example you provide is working as intended. However, I'll accept
this ticket as a documentation issue; a quick scan of the related_name
docs didn't reveal anything describing this behavior.

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

Django

unread,
Jun 15, 2011, 6:36:07 PM6/15/11
to django-...@googlegroups.com
#10913: Default related_name is broken
-------------------------------------+-------------------------------------
Reporter: neithere | Owner: nobody
Type: | Status: reopened
Cleanup/optimization | Component: Documentation
Milestone: | Severity: Normal
Version: SVN | Keywords: orm, related_name,
Resolution: | Has patch: 0
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 1 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------

Comment (by gregplaysguitar):

Fair enough, thanks for the quick response.

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

Django

unread,
Oct 2, 2013, 12:10:34 PM10/2/13
to django-...@googlegroups.com
#10913: Document how related_name affects QuerySet filtering
--------------------------------------+------------------------------------
Reporter: neithere | Owner: timo
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: orm, related_name, | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* status: new => assigned
* owner: nobody => timo


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

Django

unread,
Oct 2, 2013, 12:13:43 PM10/2/13
to django-...@googlegroups.com
#10913: Document how related_name affects QuerySet filtering
--------------------------------------+------------------------------------
Reporter: neithere | Owner: timo
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: orm, related_name, | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"75bb6ba96660e2a06e18d99120c05db2bb9fa9cc"]:
{{{
#!CommitTicketReference repository=""
revision="75bb6ba96660e2a06e18d99120c05db2bb9fa9cc"
Fixed #10913 -- Documented how related_name affects QuerySet filtering

Thanks neithere for the suggestion.
}}}

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

Django

unread,
Oct 2, 2013, 12:13:57 PM10/2/13
to django-...@googlegroups.com
#10913: Document how related_name affects QuerySet filtering
--------------------------------------+------------------------------------
Reporter: neithere | Owner: timo
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: orm, related_name, | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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

In [changeset:"06b149e220f98cd643a4445db1b5719daac0d56f"]:
{{{
#!CommitTicketReference repository=""
revision="06b149e220f98cd643a4445db1b5719daac0d56f"
[1.6.x] Fixed #10913 -- Documented how related_name affects QuerySet
filtering

Thanks neithere for the suggestion.

Backport of 75bb6ba966 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages