mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #30498 -- Fixed proxy class caching in lazy().
lazy() should prepare the proxy class only once (the first time it's
used) not on every call.
Regression in b4e76f30d1.
This commit is contained in:
committed by
Mariusz Felisiak
parent
b711eafd2a
commit
a2c31e12da
@@ -1,3 +1,5 @@
|
||||
from unittest import mock
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.functional import cached_property, lazy
|
||||
|
||||
@@ -207,3 +209,12 @@ class FunctionalTests(SimpleTestCase):
|
||||
original_object = b'J\xc3\xbcst a str\xc3\xadng'
|
||||
lazy_obj = lazy(lambda: original_object, bytes)
|
||||
self.assertEqual(repr(original_object), repr(lazy_obj()))
|
||||
|
||||
def test_lazy_class_preparation_caching(self):
|
||||
# lazy() should prepare the proxy class only once i.e. the first time
|
||||
# it's used.
|
||||
lazified = lazy(lambda: 0, int)
|
||||
__proxy__ = lazified().__class__
|
||||
with mock.patch.object(__proxy__, '__prepare_class__') as mocked:
|
||||
lazified()
|
||||
mocked.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user