[Django] #22977: No validation error when ForeignKey related_name clashes with manager name.

59 views
Skip to first unread message

Django

unread,
Jul 8, 2014, 2:56:31 AM7/8/14
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
------------------------------------------------+------------------------
Reporter: russellm | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Consider the following model definition:
{{{
class Author(models.Model):
authors = models.Manager()

name = models.CharField(max_length=100)

mentor = models.ForeignKey('self', related_name='authors')
}}}

The related name on the the foreign key clashes with the manager, so when
you try to issue a query:
{{{
Author.authors.filter(name__startswith='Douglas')
}}}

you get an error because "Author.authors has no attribute 'filter'".

The problem is order dependent; if you define the manager *after* the
foreign key, you get different errors.

I haven't checked what errors you get if you just have the default
Manager, and a related_name of 'objects'.

There may also be problems if you have a field named 'objects'.

I suspect this class of problem could be picked up by the system check
framework.

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

Django

unread,
Oct 12, 2014, 2:26:21 PM10/12/14
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
--------------------------------------+------------------------------------
Reporter: russellm | Owner: kswiat
Type: Cleanup/optimization | Status: assigned

Component: Core (System checks) | Version: 1.6
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 kswiat):

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


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

Django

unread,
Oct 13, 2014, 7:00:57 PM10/13/14
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
--------------------------------------+------------------------------------
Reporter: russellm | Owner: kswiat
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: 1.6
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 kswiat):

* has_patch: 0 => 1


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

Django

unread,
Oct 30, 2014, 1:34:22 PM10/30/14
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
--------------------------------------+------------------------------------
Reporter: russellm | Owner: kswiat
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: 1.6
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:

As Loic noted on the PR, we should revisit this after the `_meta` factor
is merged.

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

Django

unread,
Nov 1, 2014, 4:40:51 AM11/1/14
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
--------------------------------------+------------------------------------
Reporter: russellm | Owner:

Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: 1.6
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 kswiat):

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


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

Django

unread,
Jan 24, 2015, 7:06:12 AM1/24/15
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: russellm | Owner: davide-
Type: | ceretti
Cleanup/optimization | Status: assigned
Component: Core (System | Version: master
checks) |
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 davide-ceretti):

* owner: => davide-ceretti


* status: new => assigned

* version: 1.6 => master


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

Django

unread,
Jan 24, 2015, 10:08:18 AM1/24/15
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: russellm | Owner: davide-
Type: | ceretti
Cleanup/optimization | Status: assigned
Component: Core (System | Version: master
checks) |
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
-------------------------------------+-------------------------------------

Comment (by davide-ceretti):

Given loic's comment at
https://github.com/django/django/pull/3359#issuecomment-59642918, what
would be the correct implementation of this validation check? Adding it to
BaseManager.check method?

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

Django

unread,
Nov 23, 2021, 6:51:30 AM11/23/21
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
--------------------------------------+------------------------------------
Reporter: Russell Keith-Magee | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: dev
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 Mariusz Felisiak):

* owner: Davide Ceretti => (none)


* status: assigned => new


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

Django

unread,
Oct 5, 2022, 6:54:07 AM10/5/22
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Aman
Type: | Pandey
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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 Aman Pandey):

* owner: (none) => Aman Pandey


* status: new => assigned


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

Django

unread,
Nov 19, 2024, 11:11:03 PM11/19/24
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Anthony
Type: | Joseph
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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 Anthony Joseph):

* owner: (none) => Anthony Joseph
* status: new => assigned

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

Django

unread,
Nov 20, 2024, 1:57:05 AM11/20/24
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Anthony
Type: | Joseph
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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 Mariusz Felisiak):

* cc: Mariusz Felisiak (added)

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

Django

unread,
Dec 16, 2024, 7:07:10 AM12/16/24
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Anthony
Type: | Joseph
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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 Jacob Walls):

* needs_better_patch: 1 => 0

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

Django

unread,
Dec 18, 2024, 6:56:39 AM12/18/24
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Anthony
Type: | Joseph
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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 Sarah Boyce):

* needs_better_patch: 0 => 1

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

Django

unread,
Mar 18, 2025, 10:47:47 AM3/18/25
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
--------------------------------------+------------------------------------
Reporter: Russell Keith-Magee | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: dev
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 Natalia Bidart):

* owner: Anthony Joseph => (none)
* status: assigned => new

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

Django

unread,
Mar 18, 2025, 10:49:03 AM3/18/25
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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 Mariusz Felisiak):

* owner: (none) => Mariusz Felisiak
* status: new => assigned

Comment:

I will finish it.
--
Ticket URL: <https://code.djangoproject.com/ticket/22977#comment:13>

Django

unread,
Mar 27, 2025, 12:00:48 AM3/27/25
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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
-------------------------------------+-------------------------------------
Comment (by Johanan Oppong Amoateng):

Replying to [comment:13 Mariusz Felisiak]:
> I will finish it.
Hey Mariusz Felisiak are you still working on this? If not i would like to
pick it up
--
Ticket URL: <https://code.djangoproject.com/ticket/22977#comment:14>

Django

unread,
Mar 27, 2025, 2:57:28 AM3/27/25
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

Replying to [comment:14 Johanan Oppong Amoateng]:
> Replying to [comment:13 Mariusz Felisiak]:
> > I will finish it.
> Hey Mariusz Felisiak are you still working on this? If not i would like
to pick it up

It's only 9 days, pretty early to ask. I'll finish it in the coming days.
--
Ticket URL: <https://code.djangoproject.com/ticket/22977#comment:15>

Django

unread,
Mar 29, 2025, 4:38:14 PM3/29/25
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
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 Mariusz Felisiak):

* needs_better_patch: 1 => 0

Comment:

New [https://github.com/django/django/pull/19318 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/22977#comment:16>

Django

unread,
Mar 31, 2025, 7:56:06 AM3/31/25
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/22977#comment:17>

Django

unread,
Mar 31, 2025, 5:05:23 PM3/31/25
to django-...@googlegroups.com
#22977: No validation error when ForeignKey related_name clashes with manager name.
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: closed
Component: Core (System | Version: dev
checks) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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

Comment:

In [changeset:"6888375c53476011754f778deabc6cdbfa327011" 6888375c]:
{{{#!CommitTicketReference repository=""
revision="6888375c53476011754f778deabc6cdbfa327011"
Fixed #22977 -- Added system check for clashing managers and reverse
related fields.

With thanks to Konrad Świat, Loïc Bistuer, Russell Keith-Magee,
and Mariusz Felisiak.

Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22977#comment:18>
Reply all
Reply to author
Forward
0 new messages