[Django] #32294: related_name='+' doesn't work for ManyToMany fields

11 views
Skip to first unread message

Django

unread,
Dec 23, 2020, 6:55:02 AM12/23/20
to django-...@googlegroups.com
#32294: related_name='+' doesn't work for ManyToMany fields
-------------------------------------+-------------------------------------
Reporter: Aleksey | Owner: nobody
Ruban |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django raises an error during creation a db migration if two models with
the same refer to the same model in m2m field. related_name='+' or 'foo+'
don't impact anything.
In some my project there are 50 apps and almost each one has a model with
the same name. So I have to come up with a related name and write it in
for each m2m field.
Just try to make a migration for my test project
https://github.com/rafick1983/django_related_name_bug

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

Django

unread,
Dec 23, 2020, 6:57:20 AM12/23/20
to django-...@googlegroups.com
#32294: related_name='+' doesn't work for ManyToMany fields
-------------------------------------+-------------------------------------
Reporter: Aleksey Ruban | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
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
-------------------------------------+-------------------------------------
Description changed by Aleksey Ruban:

Old description:

> Django raises an error during creation a db migration if two models with
> the same refer to the same model in m2m field. related_name='+' or 'foo+'
> don't impact anything.
> In some my project there are 50 apps and almost each one has a model with
> the same name. So I have to come up with a related name and write it in
> for each m2m field.
> Just try to make a migration for my test project
> https://github.com/rafick1983/django_related_name_bug

New description:

Django raises an error during creation a db migration if two models with

the same name refer to the same model in m2m field. related_name='+' or


'foo+' don't impact anything.
In some my project there are 50 apps and almost each one has a model with
the same name. So I have to come up with a related name and write it in
for each m2m field.
Just try to make a migration for my test project
https://github.com/rafick1983/django_related_name_bug

--

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

Django

unread,
Dec 28, 2020, 2:32:59 PM12/28/20
to django-...@googlegroups.com
#32294: fields.E305 is raised on ManyToManyFields with related_name='+' in models
in different apps but with the same name.

-------------------------------------+-------------------------------------
Reporter: Aleksey Ruban | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.1
(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 Mariusz Felisiak):

* stage: Unreviewed => Accepted


Comment:

Thanks for the report. It looks that `app_label` is missing in
[https://github.com/django/django/blob/c76d51b3ad34bc2ed2155054bfb283ef53beb26a/django/db/models/fields/related.py#L1619-L1623
ManyToManyField.contribute_to_class()]:
{{{
self.remote_field.related_name = "_%s_%s_%s_+" % (cls._meta.app_label,
cls.__name__.lower(), name)
}}}

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

Django

unread,
Dec 29, 2020, 1:17:44 AM12/29/20
to django-...@googlegroups.com
#32294: fields.E305 is raised on ManyToManyFields with related_name='+' in models
in different apps but with the same name.
-------------------------------------+-------------------------------------
Reporter: Aleksey Ruban | Owner: nobody
Type: Bug | Status: new

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


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

Django

unread,
Dec 29, 2020, 8:04:02 PM12/29/20
to django-...@googlegroups.com
#32294: fields.E305 is raised on ManyToManyFields with related_name='+' in models
in different apps but with the same name.
-------------------------------------+-------------------------------------
Reporter: Aleksey Ruban | Owner: Manav
| Agarwal
Type: Bug | Status: assigned

Component: Database layer | Version: 3.1
(models, ORM) |
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 Manav Agarwal):

* owner: nobody => Manav Agarwal
* status: new => assigned


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

Django

unread,
Dec 30, 2020, 2:21:29 AM12/30/20
to django-...@googlegroups.com
#32294: fields.E305 is raised on ManyToManyFields with related_name='+' in models
in different apps but with the same name.
-------------------------------------+-------------------------------------
Reporter: Aleksey Ruban | Owner: Manav
| Agarwal
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
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 Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13822 PR]

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

Django

unread,
Dec 30, 2020, 7:13:29 AM12/30/20
to django-...@googlegroups.com
#32294: fields.E305 is raised on ManyToManyFields with related_name='+' in models
in different apps but with the same name.
-------------------------------------+-------------------------------------
Reporter: Aleksey Ruban | Owner: Manav
| Agarwal
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Dec 30, 2020, 2:13:48 PM12/30/20
to django-...@googlegroups.com
#32294: fields.E305 is raised on ManyToManyFields with related_name='+' in models
in different apps but with the same name.
-------------------------------------+-------------------------------------
Reporter: Aleksey Ruban | Owner: Manav
| Agarwal
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"a9a7421ab83361746549d574ca13438ba93c95fe" a9a7421a]:
{{{
#!CommitTicketReference repository=""
revision="a9a7421ab83361746549d574ca13438ba93c95fe"
Fixed #32294 -- Prevented ManyToManyField's hidden related name collisions
between apps.
}}}

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

Reply all
Reply to author
Forward
0 new messages