mirror of https://github.com/django/django.git
Fixed #21037 -- Made MigrationWriter raise a ValueError when serializing lambda functions.
This commit is contained in:
parent
498014ccd5
commit
adc0ab3386
|
@ -152,10 +152,12 @@ class MigrationWriter(object):
|
||||||
klass = value.im_class
|
klass = value.im_class
|
||||||
module = klass.__module__
|
module = klass.__module__
|
||||||
return "%s.%s.%s" % (module, klass.__name__, value.__name__), set(["import %s" % 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:
|
else:
|
||||||
module = value.__module__
|
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])
|
return "%s.%s" % (module, value.__name__), set(["import %s" % module])
|
||||||
# Classes
|
# Classes
|
||||||
elif isinstance(value, type):
|
elif isinstance(value, type):
|
||||||
|
|
|
@ -60,6 +60,9 @@ class WriterTests(TestCase):
|
||||||
self.assertSerializedEqual(set([2, 3, "eighty"]))
|
self.assertSerializedEqual(set([2, 3, "eighty"]))
|
||||||
self.assertSerializedEqual({"lalalala": ["yeah", "no", "maybe"]})
|
self.assertSerializedEqual({"lalalala": ["yeah", "no", "maybe"]})
|
||||||
self.assertSerializedEqual(_('Hello'))
|
self.assertSerializedEqual(_('Hello'))
|
||||||
|
# Functions
|
||||||
|
with six.assertRaisesRegex(self, ValueError, 'Cannot serialize function: lambda'):
|
||||||
|
self.assertSerializedEqual(lambda x: 42)
|
||||||
# Datetime stuff
|
# Datetime stuff
|
||||||
self.assertSerializedEqual(datetime.datetime.utcnow())
|
self.assertSerializedEqual(datetime.datetime.utcnow())
|
||||||
self.assertSerializedEqual(datetime.datetime.utcnow)
|
self.assertSerializedEqual(datetime.datetime.utcnow)
|
||||||
|
|
Loading…
Reference in New Issue