[Django] #21893: Migrations RunPython operations seem to trip on MTI models.

26 views
Skip to first unread message

Django

unread,
Jan 29, 2014, 12:54:53 AM1/29/14
to django-...@googlegroups.com
#21893: Migrations RunPython operations seem to trip on MTI models.
----------------------------+-------------------------
Reporter: loic84 | Owner:
Type: Bug | Status: new
Component: Migrations | Version: 1.7-alpha-1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------
The attached tests demonstrate 2 issues:

- The pk isn't assigned after a call to `objects.create()`, although I can
confirm that the object is properly created.

{{{
pony = ShetlandPony.objects.create()
self.assertIsNot(pony.pk, None)
}}}

- `objects.create()` doesn't accept any arguments that refer to
superclasses' fields:

{{{
>>> pony = ShetlandPony.objects.create(weight=5)
Traceback (most recent call last):
File "/Users/loic/Dev/django/tests/migrations/test_operations.py", line
544, in test_run_python
operation.database_forwards("test_runpython", editor, project_state,
new_state)
File
"/Users/loic/Dev/django/django/db/migrations/operations/special.py", line
141, in database_forwards
self.code(models=from_state.render(), schema_editor=schema_editor)
File "/Users/loic/Dev/django/tests/migrations/test_operations.py", line
538, in create_shetlandponies
pony2 = ShetlandPony.objects.create(weight=5)
File "/Users/loic/Dev/django/django/db/models/manager.py", line 92, in
manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/loic/Dev/django/django/db/models/query.py", line 364, in
create
obj = self.model(**kwargs)
File "/Users/loic/Dev/django/django/db/models/base.py", line 465, in
__init__
raise TypeError("'%s' is an invalid keyword argument for this
function" % list(kwargs)[0])
TypeError: 'weight' is an invalid keyword argument for this function
}}}

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

Django

unread,
Jan 31, 2014, 1:09:13 PM1/31/14
to django-...@googlegroups.com
#21893: Migrations RunPython operations seem to trip on MTI models.
----------------------------+---------------------------------------

Reporter: loic84 | Owner:
Type: Bug | Status: new
Component: Migrations | Version: 1.7-alpha-1
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 timo):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Mar 4, 2014, 3:54:41 AM3/4/14
to django-...@googlegroups.com
#21893: Migrations RunPython operations seem to trip on MTI models.
----------------------------+---------------------------------------

Reporter: loic84 | Owner:
Type: Bug | Status: new
Component: Migrations | Version: 1.7-alpha-1
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
----------------------------+---------------------------------------

Comment (by loic84):

I've looked into this further, the problem wasn't how the system dealt
with the migration that I've reproduced in the test case, but how I ended
with this migration to begin with.

I have abstract models that inherit from concrete models to add python
level functionality.

The problem is that these are ruled out by:
https://github.com/django/django/blob/master/django/db/migrations/state.py#L162.

Fixing this condition doesn’t help because `Apps.get_model()` do not
support abstract models and that's what `ModelState.render()` uses:
https://github.com/django/django/blob/master/django/db/migrations/state.py#L203

I’m not sure what’s the best course of action, something specific to
migrations, or a fix at the app registry level, maybe `include_abstract`
akin to the existing `include_auto_created`, `include_deferred`,
`include_swapped`.

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

Django

unread,
Mar 4, 2014, 3:21:48 PM3/4/14
to django-...@googlegroups.com
#21893: Migrations RunPython operations seem to trip on MTI models.
----------------------------+---------------------------------------

Reporter: loic84 | Owner:
Type: Bug | Status: new
Component: Migrations | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* has_patch: 0 => 1


Comment:

PR https://github.com/django/django/pull/2396.

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

Django

unread,
Mar 4, 2014, 3:34:04 PM3/4/14
to django-...@googlegroups.com
#21893: Migrations RunPython operations seem to trip on MTI models.
-------------------------------------+-------------------------------------
Reporter: loic84 | Owner: Loic
Type: Bug | Bistuer <loic.bistuer@…>
Component: Migrations | Status: closed
Severity: Normal | Version:
Keywords: | 1.7-alpha-1
Has patch: 1 | Resolution: fixed
Needs tests: 0 | Triage Stage: Accepted
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Andrew Godwin <andrew@…>):

In [changeset:"8fcc0140d075688e7b0565dea225f4380fc638c4"]:
{{{
#!CommitTicketReference repository=""
revision="8fcc0140d075688e7b0565dea225f4380fc638c4"
Merge pull request #2396 from loic/ticket21893

Fixed #21893 -- ModelState didn't account for MTI parents inherited from
abstract models.
}}}

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

Django

unread,
Mar 4, 2014, 3:34:04 PM3/4/14
to django-...@googlegroups.com
#21893: Migrations RunPython operations seem to trip on MTI models.
-------------------------------------+-------------------------------------
Reporter: loic84 | Owner: Loic
Type: Bug | Bistuer <loic.bistuer@…>
Component: Migrations | Status: closed
Severity: Normal | Version:
Keywords: | 1.7-alpha-1
Has patch: 1 | Resolution: fixed
Needs tests: 0 | Triage Stage: Accepted
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Loic Bistuer <loic.bistuer@…>):

* owner: => Loic Bistuer <loic.bistuer@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"6436f1fad9ce51f18735106ac75aeea3d6d1f310"]:
{{{
#!CommitTicketReference repository=""
revision="6436f1fad9ce51f18735106ac75aeea3d6d1f310"


Fixed #21893 -- ModelState didn't account for MTI parents inherited from
abstract models.
}}}

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

Reply all
Reply to author
Forward
0 new messages