--
Ticket URL: <https://code.djangoproject.com/ticket/23288>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* severity: Normal => Release blocker
* needs_tests: => 0
* needs_docs: => 0
Comment:
Yikes! I regret to say I can reproduce this. And it happens even without
the Profile-User change to your models.py.
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:1>
Comment (by collinanderson):
I'm out of time, but I put the example on github if someone else wants to
give it a try.
compare running the this code by hand in the shell vs in the migration
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:2>
* cc: info@… (added)
* needs_tests: 0 => 1
Comment:
I can confirm the issue too. The repository holds a simplified test case:
https://github.com/collinanderson/ticket23288
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:3>
* cc: cmawebsite@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:4>
* status: new => assigned
* owner: nobody => andrewgodwin
Comment:
Looking at this now.
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:5>
Comment (by andrewgodwin):
Well that was nasty. The root cause was that `deconstruct()` wasn't
including `related_name`, and so both the FK and the M2M ended up with the
same related_name - and without model validation running against the
migration models (as they're supposedly already validated if deconstruct
is accurate) Django didn't catch this and so the filter it passed to the
query backend was `team__id = X`, and Django picked the first thing it
knew about with a `related_name` of `"team"` - the ForeignKey, not the
ManyToMany.
The fix makes sure deconstruct also knows about related_name and a bunch
of other similar fields that were missing before (most notably, I have
left out `limit_choices_to` for now as it has no database or model layer
effect and returns a set of mostly unserialisable things).
If you have existing migrations from before the fix, you'll either need to
regenerate them or manually add `related_name` into the field definitions
yourself (doing this makes the supplied test case pass for me).
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"4d2f9c38e835383fe42548353890ed4a302eaa58"]:
{{{
#!CommitTicketReference repository=""
revision="4d2f9c38e835383fe42548353890ed4a302eaa58"
Fixed #23288: deconstruct() ignoring related_name
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:7>
* status: closed => new
* has_patch: 0 => 1
* resolution: fixed =>
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
Comment:
Could use a [1.7.x] backport.
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:8>
* status: new => closed
* resolution: => fixed
Comment:
sorry nevermind. it's right here, the trac hook must have not worked:
https://github.com/django/django/commit/b5784048e085e8db5d0e959c12278ef727994e98
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"1d79d08d9aef1565cf56d50f0742285efae53631"]:
{{{
#!CommitTicketReference repository=""
revision="1d79d08d9aef1565cf56d50f0742285efae53631"
Fixed #23294 -- Add related_name to existing migrations.
Thanks to Florian Apolloner for the review; refs #23288.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"41cf159c0ac0a7380874cb6f17464dd741ad1d9b"]:
{{{
#!CommitTicketReference repository=""
revision="41cf159c0ac0a7380874cb6f17464dd741ad1d9b"
[1.7.x] Fixed #23294 -- Add related_name to existing migrations.
Thanks to Florian Apolloner for the review; refs #23288.
Backport of 1d79d08d9a from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23288#comment:11>