mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Refs #34822 -- Added tests for serializing decorated functions in migrations.
Functions decorated with a decorator that is properly wrapped, e.g. by using `@functools.wraps`, are already supported.
This commit is contained in:
parent
0e540fca13
commit
c131949e3e
@ -783,7 +783,12 @@ Django can serialize the following:
|
|||||||
- ``LazyObject`` instances which wrap a serializable value.
|
- ``LazyObject`` instances which wrap a serializable value.
|
||||||
- Enumeration types (e.g. ``TextChoices`` or ``IntegerChoices``) instances.
|
- Enumeration types (e.g. ``TextChoices`` or ``IntegerChoices``) instances.
|
||||||
- Any Django field
|
- Any Django field
|
||||||
- Any function or method reference (e.g. ``datetime.datetime.today``) (must be in module's top-level scope)
|
- Any function or method reference (e.g. ``datetime.datetime.today``) (must be
|
||||||
|
in module's top-level scope)
|
||||||
|
|
||||||
|
- Functions may be decorated if wrapped properly, i.e. using
|
||||||
|
:func:`functools.wraps`
|
||||||
|
|
||||||
- Unbound methods used from within the class body
|
- Unbound methods used from within the class body
|
||||||
- Any class reference (must be in module's top-level scope)
|
- Any class reference (must be in module's top-level scope)
|
||||||
- Anything with a custom ``deconstruct()`` method (:ref:`see below <custom-deconstruct-method>`)
|
- Anything with a custom ``deconstruct()`` method (:ref:`see below <custom-deconstruct-method>`)
|
||||||
|
@ -77,6 +77,19 @@ class IntFlagEnum(enum.IntFlag):
|
|||||||
B = 2
|
B = 2
|
||||||
|
|
||||||
|
|
||||||
|
def decorator(f):
|
||||||
|
@functools.wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
def function_with_decorator():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class OperationWriterTests(SimpleTestCase):
|
class OperationWriterTests(SimpleTestCase):
|
||||||
def test_empty_signature(self):
|
def test_empty_signature(self):
|
||||||
operation = custom_migration_operations.operations.TestOperation()
|
operation = custom_migration_operations.operations.TestOperation()
|
||||||
@ -566,6 +579,9 @@ class WriterTests(SimpleTestCase):
|
|||||||
self.assertEqual(string, "models.SET(42)")
|
self.assertEqual(string, "models.SET(42)")
|
||||||
self.serialize_round_trip(models.SET(42))
|
self.serialize_round_trip(models.SET(42))
|
||||||
|
|
||||||
|
def test_serialize_decorated_functions(self):
|
||||||
|
self.assertSerializedEqual(function_with_decorator)
|
||||||
|
|
||||||
def test_serialize_datetime(self):
|
def test_serialize_datetime(self):
|
||||||
self.assertSerializedEqual(datetime.datetime.now())
|
self.assertSerializedEqual(datetime.datetime.now())
|
||||||
self.assertSerializedEqual(datetime.datetime.now)
|
self.assertSerializedEqual(datetime.datetime.now)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user