#28250: migration depending on non-existing legacy migration
-------------------------------+------------------------------------
Reporter: Brian May | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: master
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 Marten Kenbeek):
* cc: marten.knbk@… (added)
* version: 1.10 => master
* stage: Unreviewed => Accepted
Comment:
Ideally, an exception will still be raised if the initial migration that
may be faked is in the same app as an applied migration that depends on
it. So if `app1.0001` is not applied, but is an initial migration that may
be faked, and `app1.0002` is recorder as applied, it will still be an
error. The executor should never apply `app1.0002` without faking
`app1.0001`, so that state should be unreachable under normal
circumstances.
I believe you can check this with `if migration[0] != parent[0]`.
I've written the following test for you branch, which should go into
`migrations.test_loader.LoaderTests`:
{{{
@override_settings(MIGRATION_MODULES={
"migrations": "migrations.test_migrations_first",
"migrations2": "migrations2.test_migrations_2_first",
})
@modify_settings(INSTALLED_APPS={'append': 'migrations2'})
@mock.patch.object(MigrationLoader, 'detect_soft_applied',
return_value=(True, None))
def test_check_consistent_history_fake_initial(self):
loader = MigrationLoader(connection)
recorder = MigrationRecorder(connection)
recorder.record_applied('migrations2', '0001_initial')
recorder.record_applied('migrations2', '0002_second')
loader.check_consistent_history(connection, fake_initial=True)
recorder.record_applied('migrations', 'second')
msg = (
"Migration migrations.second is applied before its dependency
"
"migrations.thefirst on database 'default'."
)
with self.assertRaisesMessage(InconsistentMigrationHistory, msg):
loader.check_consistent_history(connection, fake_initial=True)
}}}
This also tests for the same-app scenario. I haven't checked if the test
is actually correct, and my mocking skills aren't too sharp, but this
should get you a long way.
Note that `detect_soft_applied` returns a 2-tuple of `(<is_applied>,
<state_after_migration>)`, so you need to check for the first item in the
return value.
--
Ticket URL: <https://code.djangoproject.com/ticket/28250#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.9f3410fae7f14908525e7e21630ed22d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.