#25192: Can't Squash Migration that uses migrations.RunPython.noop in Python 2
-----------------------------+------------------------------------
     Reporter:  James Pulec  |                    Owner:  nobody
         Type:  Bug          |                   Status:  new
    Component:  Migrations   |                  Version:  1.8
     Severity:  Normal       |               Resolution:
     Keywords:  py2          |             Triage Stage:  Accepted
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+------------------------------------
Changes (by Shai Berger):

 * cc: Shai Berger (added)


Comment:

 I found a funny workaround: In my project, I added this `squashmigrations`
 command (that is, a file `management/commands/squashmigrations.py` in one
 of my projects' apps):
 {{{
 """
 A squashmigrations command which does some monkeypatching on the RunPython
 operation
 to allow squashing migrations which use RunPython.noop, even on Python 2
 """
 from django.core.management.commands.squashmigrations import Command as
 DjangoCommand
 from django.db.migrations import RunPython


 # A staticmethod decorator is needed (out of a class!) because we are
 going to
 # monkeypatch this function into a class and it will be introspected by
 code that
 # will think it is an unbound instance method without the decorator.
 @staticmethod
 def noop(apps, schema_editor):
     return None


 class Command(DjangoCommand):

     def handle(self, **options):
         # Monkeypatch
         RunPython.noop = noop
         # Invoke original
         return super(Command, self).handle(**options)
 }}}
 Note the oddity of the `@staticmethod` decorator on a function that isn't
 in a class.

 I suppose we could use the same idea in fixing the bug in Django as
 well...

--
Ticket URL: <https://code.djangoproject.com/ticket/25192#comment:4>
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/064.43980280e8624fdb360abc3fe2888526%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to