Loading django/utils/functional.py +4 −0 Original line number Diff line number Diff line Loading @@ -222,6 +222,10 @@ class LazyObject(object): By subclassing, you have the opportunity to intercept and alter the instantiation. If you don't need to do that, use SimpleLazyObject. """ # Avoid infinite recursion when tracing __init__ (#19456). _wrapped = None def __init__(self): self._wrapped = empty Loading tests/utils_tests/simplelazyobject.py +14 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from __future__ import unicode_literals import copy import pickle import sys from django.utils import six from django.utils.unittest import TestCase Loading Loading @@ -138,3 +139,16 @@ class TestUtilsSimpleLazyObject(TestCase): del lazydict['one'] with self.assertRaises(KeyError): lazydict['one'] def test_trace(self): # See ticket #19456 old_trace_func = sys.gettrace() try: def trace_func(frame, event, arg): frame.f_locals['self'].__class__ if old_trace_func is not None: old_trace_func(frame, event, arg) sys.settrace(trace_func) SimpleLazyObject(None) finally: sys.settrace(old_trace_func) Loading
django/utils/functional.py +4 −0 Original line number Diff line number Diff line Loading @@ -222,6 +222,10 @@ class LazyObject(object): By subclassing, you have the opportunity to intercept and alter the instantiation. If you don't need to do that, use SimpleLazyObject. """ # Avoid infinite recursion when tracing __init__ (#19456). _wrapped = None def __init__(self): self._wrapped = empty Loading
tests/utils_tests/simplelazyobject.py +14 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from __future__ import unicode_literals import copy import pickle import sys from django.utils import six from django.utils.unittest import TestCase Loading Loading @@ -138,3 +139,16 @@ class TestUtilsSimpleLazyObject(TestCase): del lazydict['one'] with self.assertRaises(KeyError): lazydict['one'] def test_trace(self): # See ticket #19456 old_trace_func = sys.gettrace() try: def trace_func(frame, event, arg): frame.f_locals['self'].__class__ if old_trace_func is not None: old_trace_func(frame, event, arg) sys.settrace(trace_func) SimpleLazyObject(None) finally: sys.settrace(old_trace_func)