[Django] #24110: Related models in migration state are sometimes strings and not models

16 views
Skip to first unread message

Django

unread,
Jan 9, 2015, 5:21:52 PM1/9/15
to django-...@googlegroups.com
#24110: Related models in migration state are sometimes strings and not models
---------------------------------+---------------------
Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+---------------------
In some edge cases, I think, related models in the migration state are
referenced via strings rather than `__fake__` models. This is related to
#23745 and 1aa3e09c2043c88a760e8b73fb95dc8f1ffef50e

{{{#!python
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/markus/Coding/django/django/core/management/__init__.py",
line 338, in execute_from_command_line
utility.execute()
File "/home/markus/Coding/django/django/core/management/__init__.py",
line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/markus/Coding/django/django/core/management/base.py", line
390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/markus/Coding/django/django/core/management/base.py", line
444, in execute
output = self.handle(*args, **options)
File
"/home/markus/Coding/django/django/core/management/commands/migrate.py",
line 213, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/markus/Coding/django/django/db/migrations/executor.py", line
73, in migrate
state = self.unapply_migration(state, migration, fake=fake)
File "/home/markus/Coding/django/django/db/migrations/executor.py", line
127, in unapply_migration
state = migration.unapply(state, schema_editor)
File "/home/markus/Coding/django/django/db/migrations/migration.py",
line 135, in unapply
operation.state_forwards(self.app_label, project_state)
File
"/home/markus/Coding/django/django/db/migrations/operations/models.py",
line 53, in state_forwards
list(self.managers),
File "/home/markus/Coding/django/django/db/migrations/state.py", line
39, in add_model
self.reload_model(app_label, model_name)
File "/home/markus/Coding/django/django/db/migrations/state.py", line
61, in reload_model
self._reload_one_model(rel_model._meta.app_label,
rel_model._meta.model_name)
AttributeError: 'str' object has no attribute '_meta'
}}}

I've yet to figure out when this is happening exactly.

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

Django

unread,
Jan 9, 2015, 8:44:26 PM1/9/15
to django-...@googlegroups.com
#24110: Related models in migration state are sometimes strings and not models
---------------------------------+--------------------------------------

Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Release blocker | 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 MarkusH):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

It looks like not all `_pending_lookups` in the `StateApps` get resolved.

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

Django

unread,
Jan 10, 2015, 3:05:37 PM1/10/15
to django-...@googlegroups.com
#24110: Unapplying a migration has side-effects on the ProjectState passed to the
method
---------------------------------+--------------------------------------

Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Release blocker | 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 MarkusH:

Old description:

New description:

`django.db.migrations.migration.Migration.unapply()` accepts an argument
`state` that represents the project state right before the migration is
applied. The current implementation alters this state when building the
intermediate states to which each operation rolls back, instead of using a
copy. This side effect results in errors where e.g. a model can exists in
the state, but its gone from the database.

--

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

Django

unread,
Jan 10, 2015, 3:38:15 PM1/10/15
to django-...@googlegroups.com
#24110: Unapplying a migration has side-effects on the ProjectState passed to the
method
---------------------------------+--------------------------------------
Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* needs_tests: 0 => 1
* needs_docs: 0 => 1


Comment:

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

#24099 relies on a correct behavior of `Migration.unapply()`

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

Django

unread,
Jan 10, 2015, 5:46:47 PM1/10/15
to django-...@googlegroups.com
#24110: Unapplying a migration has side-effects on the ProjectState passed to the
method
-------------------------------------+-------------------------------------

Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: 1 => 0
* stage: Unreviewed => Ready for checkin
* needs_tests: 1 => 0
* needs_docs: 1 => 0


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

Django

unread,
Jan 10, 2015, 5:49:07 PM1/10/15
to django-...@googlegroups.com
#24110: Unapplying a migration has side-effects on the ProjectState passed to the
method
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Markus Holtermann <info@…>):

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


Comment:

In [changeset:"fdc2cc948725866212a9bcc97b9b7cf21bb49b90"]:
{{{
#!CommitTicketReference repository=""
revision="fdc2cc948725866212a9bcc97b9b7cf21bb49b90"
Fixed #24110 -- Rewrote migration unapply to preserve intermediate states
}}}

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

Django

unread,
Jan 10, 2015, 6:34:10 PM1/10/15
to django-...@googlegroups.com
#24110: Unapplying a migration has side-effects on the ProjectState passed to the
method
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: master

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Markus Holtermann <info@…>):

In [changeset:"be158e36251df0b07556657da47cdaf10913c57a"]:
{{{
#!CommitTicketReference repository=""
revision="be158e36251df0b07556657da47cdaf10913c57a"
Refs #24110 -- Added a more descriptive release note and fixed a spelling
mistake.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24110#comment:6>

Django

unread,
Jan 10, 2015, 7:10:08 PM1/10/15
to django-...@googlegroups.com
#24110: Unapplying a migration has side-effects on the ProjectState passed to the
method
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: master

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Markus Holtermann <info@…>):

In [changeset:"ef5889409bba675499dfd38831358daba16811ab"]:
{{{
#!CommitTicketReference repository=""
revision="ef5889409bba675499dfd38831358daba16811ab"
[1.7.x] Fixed #24110 -- Rewrote migration unapply to preserve intermediate
states

Backport of fdc2cc948725866212a9bcc97b9b7cf21bb49b90 and
be158e36251df0b07556657da47cdaf10913c57a from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24110#comment:7>

Reply all
Reply to author
Forward
0 new messages