mirror of https://github.com/django/django.git
Refs #28358 -- Fixed infinite recursion in LazyObject.__getattribute__().
Regression in 97d7990abd
.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Co-authored-by: Theo Alexiou <theofilosalexiou@gmail.com>
This commit is contained in:
parent
a94ae4cb11
commit
b2ed0d78f2
|
@ -288,6 +288,9 @@ class LazyObject:
|
|||
self._wrapped = empty
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name == "_wrapped":
|
||||
# Avoid recursion when getting wrapped object.
|
||||
return super().__getattribute__(name)
|
||||
value = super().__getattribute__(name)
|
||||
# If attribute is a proxy method, raise an AttributeError to call
|
||||
# __getattr__() and use the wrapped object method.
|
||||
|
|
|
@ -58,6 +58,14 @@ class LazyObjectTestCase(TestCase):
|
|||
obj = self.lazy_wrap(Foo())
|
||||
self.assertEqual(obj.foo, "bar")
|
||||
|
||||
def test_getattr_falsey(self):
|
||||
class Thing:
|
||||
def __getattr__(self, key):
|
||||
return []
|
||||
|
||||
obj = self.lazy_wrap(Thing())
|
||||
self.assertEqual(obj.main, [])
|
||||
|
||||
def test_setattr(self):
|
||||
obj = self.lazy_wrap(Foo())
|
||||
obj.foo = "BAR"
|
||||
|
|
Loading…
Reference in New Issue