﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24098	Add utility function to mark RunPython operations as noops	Markus Holtermann	Tim Graham <timograham@…>	"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)
    ]
}}}"	New feature	closed	Migrations	dev	Normal	fixed			Ready for checkin	1	0	0	0	1	0
