Fixed #19456 -- Avoid infinite recursion when tracing LazyObject.__init__.

Thanks blaze33 for the patch.
This commit is contained in:
Aymeric Augustin 2013-03-18 11:22:43 +01:00
parent 0efafa4c54
commit 9dc5702932
2 changed files with 18 additions and 0 deletions

View File

@ -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 File

@ -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
@ -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)