[1.11.x] Fixed #25192 -- Fixed squashmigrations crash with RunPython.noop on Python 2.

Thanks Adam Johnson for review.
This commit is contained in:
Shai Berger 2017-01-29 00:33:13 +02:00 committed by Tim Graham
parent 76a99f1b9a
commit 437e0ba533
5 changed files with 43 additions and 0 deletions

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.db import router
from django.utils import six
from .base import Operation
@ -203,3 +204,11 @@ class RunPython(Operation):
@staticmethod
def noop(apps, schema_editor):
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)

View File

@ -1392,3 +1392,7 @@ class SquashMigrationsTests(MigrationTestBase):
)
with self.assertRaisesMessage(CommandError, msg):
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)

View File

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
initial = True
operations = []

View File

@ -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),
]