[Django] #27903: RenameModel does not not change ForeignKey with related_name='+'

14 views
Skip to first unread message

Django

unread,
Mar 4, 2017, 2:04:01 PM3/4/17
to django-...@googlegroups.com
#27903: RenameModel does not not change ForeignKey with related_name='+'
-----------------------------------------------+------------------------
Reporter: Alexander Schrijver | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.10
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 |
-----------------------------------------------+------------------------
When you create a ForeignKey with a related_name='+' to a second model,
and you rename the second model, the model which is referred in the
ForeignKey is not updated. I've created a updated
OperationTests.test_rename_model test to show this (I'll update this
ticket when I've created the PR). This only affects 1.10, this issue seems
to be fixed in 1.11.

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

Django

unread,
Mar 4, 2017, 2:12:06 PM3/4/17
to django-...@googlegroups.com
#27903: RenameModel does not not change ForeignKey with related_name='+'
-------------------------------------+-------------------------------------

Reporter: Alexander Schrijver | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.10
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 Alexander Schrijver:

Old description:

> When you create a ForeignKey with a related_name='+' to a second model,
> and you rename the second model, the model which is referred in the
> ForeignKey is not updated. I've created a updated
> OperationTests.test_rename_model test to show this (I'll update this
> ticket when I've created the PR). This only affects 1.10, this issue
> seems to be fixed in 1.11.

New description:

When you create a ForeignKey with a related_name='+' to a second model,
and you rename the second model, the model which is referred in the
ForeignKey is not updated. I've created a updated

OperationTests.test_rename_model test to show this (PR:
https://github.com/django/django/pull/8146). This only affects 1.10, this


issue seems to be fixed in 1.11.

--

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

Django

unread,
Mar 4, 2017, 2:21:31 PM3/4/17
to django-...@googlegroups.com
#27903: RenameModel does not not change ForeignKey with related_name='+'
-------------------------------------+-------------------------------------

Reporter: Alexander Schrijver | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
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
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* component: Uncategorized => Migrations


Comment:

I assume this was fixed by the `RenameModel` refactor in #27310 as we
don't rely on ''related objects'' anymore (which can be missing when
`related_name` ends with `'+'`).

I'm not sure this is worth fixing at this point in the 1.10 release cycle.

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

Django

unread,
Mar 4, 2017, 10:53:33 PM3/4/17
to django-...@googlegroups.com
#27903: RenameModel does not not change ForeignKey with related_name='+'
-------------------------------------+-------------------------------------

Reporter: Alexander Schrijver | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

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


Comment:

I agree with Simon.

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

Django

unread,
Mar 5, 2017, 10:52:38 AM3/5/17
to django-...@googlegroups.com
#27903: RenameModel does not not change ForeignKey with related_name='+'
-------------------------------------+-------------------------------------

Reporter: Alexander Schrijver | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Alexander Schrijver):

As a workaround you can do is: before the RenameModel with a AlterField
set the ForeignKey's related_name to some temporary value, and then set it
back to '+' when you've done the RenameModel. e.g.:

{{{
migrations.AlterField(
model_name='SomeModel',
name='some_field',
field=models.ForeignKey(... related_name='xxx', to='app.OtherModel'),
),
migrations.RenameModel('OtherModel', 'OtherModel2'),
migrations.AlterField(
model_name='SomeModel',
name='some_field',
field=models.ForeignKey(... related_name='+', to='app.OtherModel2'),
),
}}}

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

Reply all
Reply to author
Forward
0 new messages