[1.11.x] Fixed #25192 -- Fixed squashmigrations crash with RunPython.noop on Python 2.
Thanks Adam Johnson for review.
This commit is contained in:
parent
76a99f1b9a
commit
437e0ba533
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import router
|
from django.db import router
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
from .base import Operation
|
from .base import Operation
|
||||||
|
|
||||||
|
@ -203,3 +204,11 @@ class RunPython(Operation):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def noop(apps, schema_editor):
|
def noop(apps, schema_editor):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
# Allow migrations using RunPython.noop to be squashed on Python 2 (it doesn't
|
||||||
|
# support serializating unbound method so install a module function instead).
|
||||||
|
if six.PY2:
|
||||||
|
def noop(apps, schema_editor):
|
||||||
|
return None
|
||||||
|
RunPython.noop = staticmethod(noop)
|
||||||
|
|
|
@ -1392,3 +1392,7 @@ class SquashMigrationsTests(MigrationTestBase):
|
||||||
)
|
)
|
||||||
with self.assertRaisesMessage(CommandError, msg):
|
with self.assertRaisesMessage(CommandError, msg):
|
||||||
call_command("squashmigrations", "migrations", "0003", "0002", interactive=False, verbosity=0)
|
call_command("squashmigrations", "migrations", "0003", "0002", interactive=False, verbosity=0)
|
||||||
|
|
||||||
|
def test_squashmigrations_squashes_noop(self):
|
||||||
|
with self.temporary_migration_module(module="migrations.test_migrations_squash_noop"):
|
||||||
|
call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=0)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
operations = []
|
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def dummy_python_op(apps, schema_editor):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("migrations", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(dummy_python_op, migrations.RunPython.noop, elidable=False),
|
||||||
|
]
|
Loading…
Reference in New Issue