Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21037 -- Made MigrationWriter raise a ValueError when serializ…

…ing lambda functions.
  • Loading branch information...
commit adc0ab3386520874dbc96c2f905fd66769b8f16d 1 parent 498014c
@loic loic authored timgraham committed
View
6 django/db/migrations/writer.py
@@ -152,10 +152,12 @@ def serialize(cls, value):
klass = value.im_class
module = klass.__module__
return "%s.%s.%s" % (module, klass.__name__, value.__name__), set(["import %s" % module])
+ elif value.__name__ == '<lambda>':
+ raise ValueError("Cannot serialize function: lambda")
+ elif value.__module__ is None:
+ raise ValueError("Cannot serialize function %r: No module" % value)
else:
module = value.__module__
- if module is None:
- raise ValueError("Cannot serialize function %r: No module" % value)
return "%s.%s" % (module, value.__name__), set(["import %s" % module])
# Classes
elif isinstance(value, type):
View
3  tests/migrations/test_writer.py
@@ -60,6 +60,9 @@ def test_serialize(self):
self.assertSerializedEqual(set([2, 3, "eighty"]))
self.assertSerializedEqual({"lalalala": ["yeah", "no", "maybe"]})
self.assertSerializedEqual(_('Hello'))
+ # Functions
+ with six.assertRaisesRegex(self, ValueError, 'Cannot serialize function: lambda'):
+ self.assertSerializedEqual(lambda x: 42)
# Datetime stuff
self.assertSerializedEqual(datetime.datetime.utcnow())
self.assertSerializedEqual(datetime.datetime.utcnow)
Please sign in to comment.
Something went wrong with that request. Please try again.