[Django] #24098: Add utility function to mark RunPython operations as noops

37 views
Skip to first unread message

Django

unread,
Jan 8, 2015, 9:21:13 AM1/8/15
to django-...@googlegroups.com
#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.

Django

unread,
Jan 8, 2015, 10:13:11 AM1/8/15
to django-...@googlegroups.com
#24098: Add utility function to mark RunPython operations as noops
-----------------------------+------------------------------------

Reporter: MarkusH | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by loic):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

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 to `RunSQL.noop` for consistency with
`RunPython`.

--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:1>

Django

unread,
Jan 8, 2015, 12:09:56 PM1/8/15
to django-...@googlegroups.com
#24098: Add utility function to mark RunPython operations as noops
-----------------------------+------------------------------------

Reporter: MarkusH | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by MarkusH):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/3859

--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:2>

Django

unread,
Jan 9, 2015, 8:38:25 AM1/9/15
to django-...@googlegroups.com
#24098: Add utility function to mark RunPython operations as noops
-----------------------------+---------------------------------------------

Reporter: MarkusH | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:3>

Django

unread,
Jan 9, 2015, 10:47:30 AM1/9/15
to django-...@googlegroups.com
#24098: Add utility function to mark RunPython operations as noops
-------------------------------------+-------------------------------------
Reporter: MarkusH | Owner: Tim
| Graham <timograham@…>
Type: New feature | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* owner: => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"c8bac4b556cf4716dc9003e5da48060cb72ba7cb"]:
{{{
#!CommitTicketReference repository=""
revision="c8bac4b556cf4716dc9003e5da48060cb72ba7cb"
Fixed #24098 -- Added no-op attributes to RunPython and RunSQL

Thanks Loïc Bistuer and Tim Graham for the discussion and review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24098#comment:4>

Reply all
Reply to author
Forward
0 new messages