[Django] #32310: ManyToManyField.through docs clarification

21 views
Skip to first unread message

Django

unread,
Jan 2, 2021, 11:28:40 AM1/2/21
to django-...@googlegroups.com
#32310: ManyToManyField.through docs clarification
------------------------------------------------+------------------------
Reporter: Fabio Sangiovanni | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Hello and happy new year everyone!

A note in the current `ManyToManyField.through` docs
(https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyField.through)
suggests that:

> Recursive relationships using an intermediary model and defined as
symmetrical (that is, with symmetrical=True, which is the default) can’t
determine the reverse accessors names, as they would be the same.

But the value of the `symmetrical` argument seems irrelevant in this
regard, since in both cases (`True` or `False` value) the system checks
framework raises the same error (`fields.E304`).

Repro:


{{{
from django.db import models


class Relationship(models.Model):
person1 = models.ForeignKey('Person', on_delete=models.CASCADE)
person2 = models.ForeignKey('Person', on_delete=models.CASCADE)


class Person(models.Model):
other = models.ManyToManyField('self', through=Relationship,
symmetrical=False)
}}}

`manage.py makemigrations` yields:

{{{
SystemCheckError: System check identified some issues:

ERRORS:
app.Relationship.person1: (fields.E304) Reverse accessor for
'Relationship.person1' clashes with reverse accessor for
'Relationship.person2'.
HINT: Add or change a related_name argument to the definition for
'Relationship.person1' or 'Relationship.person2'.
app.Relationship.person2: (fields.E304) Reverse accessor for
'Relationship.person2' clashes with reverse accessor for
'Relationship.person1'.
HINT: Add or change a related_name argument to the definition for
'Relationship.person2' or 'Relationship.person1'.
}}}

for both values of the `symmetrical` argument of `ManyToManyField`.


Am I missing something?

Thanks!

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

Django

unread,
Jan 4, 2021, 12:49:29 AM1/4/21
to django-...@googlegroups.com
#32310: Clarify ManyToManyField.through note about reverse accessors names for non-
symmetrical recursive relationships.
--------------------------------------+------------------------------------

Reporter: Fabio Sangiovanni | 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: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Good catch. IMO we can chop: ''"and defined as symmetrical (that is, with
symmetrical=True, which is the default)"''. Would you like to prepare a
patch?

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

Django

unread,
Jan 4, 2021, 8:15:29 AM1/4/21
to django-...@googlegroups.com
#32310: Clarify ManyToManyField.through note about reverse accessors names for non-
symmetrical recursive relationships.
--------------------------------------+------------------------------------
Reporter: Fabio Sangiovanni | 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: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Fabio Sangiovanni):

Sure, I'm happy to open a PR for this. Will do as soon as I can.

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

Django

unread,
Jan 4, 2021, 8:16:53 AM1/4/21
to django-...@googlegroups.com
#32310: Clarify ManyToManyField.through note about reverse accessors names for non-
symmetrical recursive relationships.
-------------------------------------+-------------------------------------
Reporter: Fabio Sangiovanni | Owner: Fabio
Type: | Sangiovanni
Cleanup/optimization | Status: assigned
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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Fabio Sangiovanni):

* owner: nobody => Fabio Sangiovanni
* status: new => assigned


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

Django

unread,
Jan 4, 2021, 12:52:30 PM1/4/21
to django-...@googlegroups.com
#32310: Clarify ManyToManyField.through note about reverse accessors names for non-
symmetrical recursive relationships.
-------------------------------------+-------------------------------------
Reporter: Fabio Sangiovanni | Owner: Fabio
Type: | Sangiovanni
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 Fabio Sangiovanni):

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
Jan 4, 2021, 4:21:39 PM1/4/21
to django-...@googlegroups.com
#32310: Clarify ManyToManyField.through note about reverse accessors names for non-
symmetrical recursive relationships.
-------------------------------------+-------------------------------------
Reporter: Fabio Sangiovanni | Owner: Fabio
Type: | Sangiovanni
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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"2d6c9b97bc706aab1975f57e814461e90e389bb0" 2d6c9b9]:
{{{
#!CommitTicketReference repository=""
revision="2d6c9b97bc706aab1975f57e814461e90e389bb0"
Fixed #32310 -- Fixed note about reverse accessors for intermediate table
for self-referential ManyToManyField.
}}}

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

Django

unread,
Jan 4, 2021, 4:22:08 PM1/4/21
to django-...@googlegroups.com
#32310: Clarify ManyToManyField.through note about reverse accessors names for non-
symmetrical recursive relationships.
-------------------------------------+-------------------------------------
Reporter: Fabio Sangiovanni | Owner: Fabio
Type: | Sangiovanni
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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"6d3a623f713cbe0c64235458f44a1fe3a74108f8" 6d3a623]:
{{{
#!CommitTicketReference repository=""
revision="6d3a623f713cbe0c64235458f44a1fe3a74108f8"
[3.1.x] Fixed #32310 -- Fixed note about reverse accessors for


intermediate table for self-referential ManyToManyField.

Backport of 2d6c9b97bc706aab1975f57e814461e90e389bb0 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages