Opened 10 years ago
Closed 10 years ago
#24098 closed New feature (fixed)
Add utility function to mark RunPython operations as noops
Reported by: | Markus Holtermann | Owned by: | |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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:
class RunPython(Operation): # ... noop = lambda apps, schema_editor: None
Hence the migration could look like
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) ]
Change History (4)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:4 by , 10 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
As discussed on IRC we should do the same thing for
RunSQL
.An empty string
''
should work well to represent a provided no-op query but we can also alias it toRunSQL.noop
for consistency withRunPython
.