#24098: Add utility function to mark RunPython operations as noops
-----------------------------+--------------------
     Reporter:  MarkusH      |      Owner:
         Type:  New feature  |     Status:  new
    Component:  Migrations   |    Version:  master
     Severity:  Normal       |   Keywords:
 Triage Stage:  Unreviewed   |  Has patch:  0
Easy pickings:  1            |      UI/UX:  0
-----------------------------+--------------------
 When adding a field to a model and propagating new values with a
 `RunPython` operation in migrations, there is often no reason for a
 backwards function to call. Same goes for the other direction.

 However, if no backwards callable is specified, the respective migration
 isn't reversible. And the forwards callable is required.

 I propose to add a class attribute that effectively provides a no-op but
 makes the code a bit more expressive:

 {{{#!python
 class RunPython(Operation):
     # ...
     noop = lambda apps, schema_editor: None
 }}}

 Hence the migration could look like

 {{{#!python
 from django.db import migrations

 def forwards(apps, schema_editor):
     # Do some stuff

 class Migration(migrations.Migration):
     operations = [
         # Current way
         migrations.RunPython(forwards, lambda apps, schema_editor: None)
         # New approach
         migrations.RunPython(forwards, migrations.RunPython.noop)
     ]
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24098>
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/050.e1fe171f12ff6552d6420f0c9b6b967c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to