[Django] #23288: Unable to correctly access data in table during migration

11 views
Skip to first unread message

Django

unread,
Aug 13, 2014, 3:45:15 PM8/13/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
-----------------------------+----------------------
Reporter: mtthw-meyer | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+----------------------
I created a profile and then setup some relations to it. When I change the
relation from the profile to the User model and try to access the data
after the models.py file has been changed but before the migration has
been completed the members field returns only a single profile objects
instead of the ones that were assigned. Dumping the data shows that users
with id 2,3,4,5 are in team with id 1, but when accessing the field from
the migration only user id 2 is returned.

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

Django

unread,
Aug 13, 2014, 5:37:28 PM8/13/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
---------------------------------+------------------------------------

Reporter: mtthw-meyer | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | 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 collinanderson):

* 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>

Django

unread,
Aug 13, 2014, 6:04:44 PM8/13/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
---------------------------------+------------------------------------

Reporter: mtthw-meyer | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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

https://github.com/collinanderson/ticket23288/blob/d3354319e78cf46077fc46e61ff70e201704b264/example/migrations/0002_auto_20140813_1645.py#L9

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

Django

unread,
Aug 13, 2014, 10:02:04 PM8/13/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
---------------------------------+------------------------------------

Reporter: mtthw-meyer | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Markush2010):

* 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>

Django

unread,
Aug 14, 2014, 10:47:45 AM8/14/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
---------------------------------+------------------------------------

Reporter: mtthw-meyer | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by collinanderson):

* cc: cmawebsite@… (added)


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

Django

unread,
Aug 14, 2014, 10:19:13 PM8/14/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
---------------------------------+----------------------------------------
Reporter: mtthw-meyer | Owner: andrewgodwin
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7-rc-2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by andrewgodwin):

* status: new => assigned
* owner: nobody => andrewgodwin


Comment:

Looking at this now.

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

Django

unread,
Aug 14, 2014, 10:47:06 PM8/14/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
---------------------------------+----------------------------------------
Reporter: mtthw-meyer | Owner: andrewgodwin
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7-rc-2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------

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>

Django

unread,
Aug 14, 2014, 10:47:56 PM8/14/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
---------------------------------+----------------------------------------
Reporter: mtthw-meyer | Owner: andrewgodwin
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by Andrew Godwin <andrew@…>):

* 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>

Django

unread,
Aug 14, 2014, 11:11:17 PM8/14/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
-------------------------------------+-------------------------------------
Reporter: mtthw-meyer | Owner:
Type: Bug | andrewgodwin
Component: Migrations | Status: new
Severity: Release blocker | Version: 1.7-rc-2
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Ready for
Needs tests: 0 | checkin
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by collinanderson):

* 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>

Django

unread,
Aug 14, 2014, 11:20:02 PM8/14/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
-------------------------------------+-------------------------------------
Reporter: mtthw-meyer | Owner:
Type: Bug | andrewgodwin
Component: Migrations | Status: closed

Severity: Release blocker | Version: 1.7-rc-2
Keywords: | Resolution: fixed

Has patch: 1 | Triage Stage: Ready for
Needs tests: 0 | checkin
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by collinanderson):

* 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>

Django

unread,
Aug 15, 2014, 12:39:57 PM8/15/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
-------------------------------------+-------------------------------------
Reporter: mtthw-meyer | Owner:
Type: Bug | andrewgodwin
Component: Migrations | Status: closed
Severity: Release blocker | Version: 1.7-rc-2
Keywords: | Resolution: fixed
Has patch: 1 | Triage Stage: Ready for
Needs tests: 0 | checkin
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Aug 15, 2014, 1:52:50 PM8/15/14
to django-...@googlegroups.com
#23288: Unable to correctly access data in table during migration
-------------------------------------+-------------------------------------
Reporter: mtthw-meyer | Owner:
Type: Bug | andrewgodwin
Component: Migrations | Status: closed
Severity: Release blocker | Version: 1.7-rc-2
Keywords: | Resolution: fixed
Has patch: 1 | Triage Stage: Ready for
Needs tests: 0 | checkin
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages