[Django] #26230: default_related_name lookup

8 views
Skip to first unread message

Django

unread,
Feb 17, 2016, 9:51:13 AM2/17/16
to django-...@googlegroups.com
#26230: default_related_name lookup
-------------------------------+--------------------
Reporter: OmegaDroid | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
If I attach a `default_related_name` for my model using the name in a
model lookup fails.

For example, if I have the following models:

{{{
from django.db import models

class Foo(models.Model):
a = models.IntegerField(default=0)


class Bar(models.Model):
foo = models.ForeignKey(Foo, related_name='bars')


class Boo(models.Model):
foo = models.ForeignKey(Foo)

class Meta:
default_related_name = 'boos'
}}}

And the following tests:

{{{
from django.test import TestCase

from .models import Foo, Bar, Boo


class Test(TestCase):
def setUp(self):
self.foo = Foo.objects.create()

def test_related_name_on_field___all_is_fine(self):
instance = Bar.objects.create(foo=self.foo)

# get related set
self.assertEqual(instance, self.foo.bars.first())

# filter foos through lookup
self.assertEqual(self.foo, Foo.objects.get(bars=instance))

def test_related_name_is_default___lookup_fails(self):
instance = Boo.objects.create(foo=self.foo)

# get related set
self.assertEqual(instance, self.foo.boos.first())

# filter foos through lookup
self.assertEqual(self.foo, Foo.objects.get(boos=instance))
}}}

I get the following error:

{{{
django.core.exceptions.FieldError: Cannot resolve keyword 'boos' into
field. Choices are: a, bars, boo, id
}}}

This shows I can use `boos` as a property for `Foo` objects but when i try
to use it in a lookup it is expecting `boo` rather than `boos`

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

Django

unread,
Feb 17, 2016, 10:13:03 AM2/17/16
to django-...@googlegroups.com
#26230: default_related_name lookup
-------------------------------------+-------------------------------------
Reporter: OmegaDroid | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
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 charettes):

* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* version: 1.9 => master
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

This was also brought up on [https://groups.google.com/d/msg/django-
users/OGavpqJrw6g/H09wAh35CAAJ django-users] a couple of months ago.

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

Django

unread,
Feb 17, 2016, 10:20:07 AM2/17/16
to django-...@googlegroups.com
#26230: RelatedField.related_query_name should default to
_meta.default_related_name if defined.
-------------------------------------+-------------------------------------
Reporter: OmegaDroid | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
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
-------------------------------------+-------------------------------------

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

Django

unread,
Feb 23, 2016, 7:54:04 AM2/23/16
to django-...@googlegroups.com
#26230: RelatedField.related_query_name should default to
_meta.default_related_name if defined.
-------------------------------------+-------------------------------------
Reporter: OmegaDroid | Owner: chenesan
Type: Bug | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
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 chenesan):

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


Comment:

I'll work on this in the next few days.

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

Django

unread,
Feb 24, 2016, 2:31:59 AM2/24/16
to django-...@googlegroups.com
#26230: RelatedField.related_query_name should default to
_meta.default_related_name if defined.
-------------------------------------+-------------------------------------
Reporter: OmegaDroid | Owner: chenesan
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
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 chenesan):

* has_patch: 0 => 1


Comment:

PR https://github.com/django/django/pull/6187

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

Django

unread,
Feb 25, 2016, 7:07:53 PM2/25/16
to django-...@googlegroups.com
#26230: RelatedField.related_query_name should default to
_meta.default_related_name if defined.
-------------------------------------+-------------------------------------
Reporter: OmegaDroid | Owner: chenesan
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


Comment:

The pull request is backwards-incompatible. It would be nice to have a
deprecation path if possible.

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

Django

unread,
Feb 27, 2016, 8:49:14 AM2/27/16
to django-...@googlegroups.com
#26230: RelatedField.related_query_name should default to
_meta.default_related_name if defined.
-------------------------------------+-------------------------------------
Reporter: OmegaDroid | Owner: chenesan
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

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

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


Comment:

In [changeset:"b84f5ab4ec2d1edbe9a7effa9f75a3caa189bace" b84f5ab4]:
{{{
#!CommitTicketReference repository=""
revision="b84f5ab4ec2d1edbe9a7effa9f75a3caa189bace"
Fixed #26230 -- Made default_related_name affect related_query_name.
}}}

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

Django

unread,
Jan 17, 2017, 10:09:52 PM1/17/17
to django-...@googlegroups.com
#26230: RelatedField.related_query_name should default to
_meta.default_related_name if defined.
-------------------------------------+-------------------------------------
Reporter: Daniel Bate | Owner: Yi-Shan,
| Chen

Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

In [changeset:"bfe0d54514bf4f03bc4a956452541f0103134ba3" bfe0d54]:
{{{
#!CommitTicketReference repository=""
revision="bfe0d54514bf4f03bc4a956452541f0103134ba3"
Refs #26230 -- Removed support for model name query lookups when using
Meta.default_related_name.

Per deprecation timeline.
}}}

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

Reply all
Reply to author
Forward
0 new messages