Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#24354 closed Bug (fixed)

Migrations that rename subclasses cause problems with relations

Reported by: Matthew Wilkes Owned by: nobody
Component: Migrations Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

On a Django 1.7.4 site (and 1.7.x), if you have a model that is the destination of a relation and subclass that model then migrations for the subclass incorrectly cause the relations aimed at the parent to be repointed. The generated migrations look like noops, as the models in question aren't actually changed. I had this issue today on a DjangoCMS site, causing migrations to be generated in my django-cms egg.

For example:

class Author(models.Model):
    real_name = models.CharField('name', max_length=50)

class Pseudonym(Author):
    pseudonym = models.CharField('name', max_length=50)

class Book(models.Model):
    author = models.ForeignKey(Author)

If the class Pseudonym is renamed then later migrations will always attempt to reset the author field on book.

This is already fixed on 1.8 and master.

Change History (13)

comment:1 Changed 5 years ago by Matthew Wilkes

comment:2 Changed 5 years ago by Matthew Wilkes

Has patch: set
Type: UncategorizedBug

Mark as having patch.

comment:3 Changed 5 years ago by Tim Graham

Bisected the fix on master/1.8 to b29f3b51204d53c1c8745966476543d068c173a2.

Last edited 5 years ago by Tim Graham (previous) (diff)

comment:4 Changed 5 years ago by Matthew Wilkes

I'm sorry, are you asking me to bisect the current state or saying though found that commit from bisecting?

Either way, that's right. That PR fixes the issue and it was present on master immediately prior to it being merged. I know this because that's where I originally fixed it, and had to change my PR to target 1.7 as MarkusH's PR landed while I was working in it.

He advised that the changes on 1.8 would not be back ported to the 1.7 line.

comment:5 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

Sorry, I had a typo in my earlier comment; edited to fix it and reviewed your PR.

comment:6 Changed 5 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

Looks good to me, hopefully a migrations expert can give a final +1.

comment:7 Changed 5 years ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:8 Changed 5 years ago by Matthew Wilkes

I have made the requested changes and updated the pull request. Sorry for the slow!

comment:9 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In d0607a7e:

[1.7.x] Fixed #24354 -- Prevented repointing of relations on superclasses when migrating a subclass's name change

comment:10 Changed 5 years ago by Tim Graham <timograham@…>

In ae87ad0:

Refs #24354 -- Prevented repointing of relations on superclasses when migrating a subclass's name change

Forwardport of test and release note from stable/1.7.x

comment:11 Changed 5 years ago by Tim Graham <timograham@…>

In 22a67d22:

[1.8.x] Refs #24354 -- Prevented repointing of relations on superclasses when migrating a subclass's name change

Forwardport of test and release note from stable/1.7.x

Backport of ae87ad005f7b62f5fa5a29ef07443fa1bbb9baf0 from master

comment:12 Changed 5 years ago by Markus Holtermann <info@…>

In e4b7daec:

Refs #24354 -- Prevented repointing of relations on superclasses when migrating a subclass's name change

The issue was hidden on 1.8+ until #24573 due to a bug inside the model
reloading process.

Forwardport of patch from ae87ad005f7b62f5fa5a29ef07443fa1bbb9baf0

comment:13 Changed 5 years ago by Markus Holtermann <info@…>

In 697317f:

[1.8.x] Refs #24354 -- Prevented repointing of relations on superclasses when migrating a subclass's name change

The issue was hidden on 1.8+ until #24573 due to a bug inside the model
reloading process.

Forwardport of patch from ae87ad005f7b62f5fa5a29ef07443fa1bbb9baf0

Note: See TracTickets for help on using tickets.
Back to Top