diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2023-09-13 15:49:10 +0100 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2023-09-13 15:57:18 -0300 |
| commit | f92e68c30a0d38d25486e3f3cfabe5dfb5961ef7 (patch) | |
| tree | 50e5828121b673e1eb661d774c89f92b7ef86584 /tests | |
| parent | c131949e3ebd3b54ee6d4c11239401a215e5cb9b (diff) | |
Fixed #34822 -- Added support for serializing functions decorated with functools.lru_cache in migrations.
`@functools.cache` and `@functools.lru_cache` return an object of type
`functools._lru_cache_wrapper` which prevented the migrations serializer from
working. Simply using the existing `FunctionTypeSerializer` for this additional
type works as expected.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_writer.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index e7c7917ef0..fd0e7f0fe3 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -90,6 +90,16 @@ def function_with_decorator(): pass +@functools.cache +def function_with_cache(): + pass + + +@functools.lru_cache(maxsize=10) +def function_with_lru_cache(): + pass + + class OperationWriterTests(SimpleTestCase): def test_empty_signature(self): operation = custom_migration_operations.operations.TestOperation() @@ -581,6 +591,8 @@ class WriterTests(SimpleTestCase): def test_serialize_decorated_functions(self): self.assertSerializedEqual(function_with_decorator) + self.assertSerializedEqual(function_with_cache) + self.assertSerializedEqual(function_with_lru_cache) def test_serialize_datetime(self): self.assertSerializedEqual(datetime.datetime.now()) |
