From 98dd8dd02e6a005266866ab1cb4a2ec00dce0193 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 9 Feb 2014 10:54:02 +0000 Subject: Fixed #21892: RunPython no longer accepts strings --- django/db/migrations/operations/special.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'django/db') diff --git a/django/db/migrations/operations/special.py b/django/db/migrations/operations/special.py index 65fd8125fc..8d001034ad 100644 --- a/django/db/migrations/operations/special.py +++ b/django/db/migrations/operations/special.py @@ -109,22 +109,15 @@ class RunPython(Operation): def __init__(self, code, reverse_code=None): # Forwards code - if isinstance(code, six.string_types): - # Trim any leading whitespace that is at the start of all code lines - # so users can nicely indent code in migration files - code = textwrap.dedent(code) - # Run the code through a parser first to make sure it's at least - # syntactically correct - self.code = compile(code, "", "exec") - else: - self.code = code + if not callable(code): + raise ValueError("RunPython must be supplied with a callable") + self.code = code # Reverse code if reverse_code is None: self.reverse_code = None - elif isinstance(reverse_code, six.string_types): - reverse_code = textwrap.dedent(reverse_code) - self.reverse_code = compile(reverse_code, "", "exec") else: + if not callable(reverse_code): + raise ValueError("RunPython must be supplied with callable arguments") self.reverse_code = reverse_code def state_forwards(self, app_label, state): -- cgit v1.3