Fixed #19456 -- Avoid infinite recursion when tracing LazyObject.__init__.
Thanks blaze33 for the patch.
This commit is contained in:
parent
0efafa4c54
commit
9dc5702932
|
@ -222,6 +222,10 @@ class LazyObject(object):
|
||||||
By subclassing, you have the opportunity to intercept and alter the
|
By subclassing, you have the opportunity to intercept and alter the
|
||||||
instantiation. If you don't need to do that, use SimpleLazyObject.
|
instantiation. If you don't need to do that, use SimpleLazyObject.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Avoid infinite recursion when tracing __init__ (#19456).
|
||||||
|
_wrapped = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._wrapped = empty
|
self._wrapped = empty
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import pickle
|
import pickle
|
||||||
|
import sys
|
||||||
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.unittest import TestCase
|
from django.utils.unittest import TestCase
|
||||||
|
@ -138,3 +139,16 @@ class TestUtilsSimpleLazyObject(TestCase):
|
||||||
del lazydict['one']
|
del lazydict['one']
|
||||||
with self.assertRaises(KeyError):
|
with self.assertRaises(KeyError):
|
||||||
lazydict['one']
|
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…
Reference in New Issue