Commit 9dc57029 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

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

Thanks blaze33 for the patch.
parent 0efafa4c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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

+14 −0
Original line number Diff line number Diff line
@@ -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)