Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19456 -- Avoid infinite recursion when tracing LazyObject.__in…

…it__.

Thanks blaze33 for the patch.
  • Loading branch information...
commit 9dc5702932a0031bc4fb5473f2cdccffc61dbe30 1 parent 0efafa4
@aaugustin aaugustin authored
View
4 django/utils/functional.py
@@ -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
View
14 tests/utils_tests/simplelazyobject.py
@@ -2,6 +2,7 @@
import copy
import pickle
+import sys
from django.utils import six
from django.utils.unittest import TestCase
@@ -138,3 +139,16 @@ def test_dict(self):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.