Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Doesn't work with Django's SimpleLazyObject #92

Closed
valtron opened this Issue · 4 comments

4 participants

@valtron

I'm using pycallgraph 0.5.1, Django 1.3.1, Python 2.7.2 32bit.

Line 235 of pycallgraph.py, which gets the "__class__" of "self" in the current call being traced, causes an infinite loop. The method being traced is SimpleLazyObject's "__init__", which among other things sets "self._wrapped". ".__class__" triggers the "__get_class" method on the object, which checks if "_wrapped" is None, but since the constructor hasn't run yet (it was intercepted by the tracer), this gets translated into a "__getattr__" call on the object, which again checks if "_wrapped" is None... etc.

Here is the relevant part the stack trace. I used custom middleware to integrate pycallgraph in Django.

C:\Python27\lib\site-packages\django\contrib\auth\context_processors.py in auth
  57. 'user': SimpleLazyObject(get_user),
C:\Python27\lib\site-packages\django\utils\functional.py in __init__
  316. def __init__(self, func):
C:\Python27\lib\site-packages\pycallgraph.py in tracer
  235. class_name = frame.f_locals['self'].__class__.__name__
C:\Python27\lib\site-packages\django\utils\functional.py in __get_class
  354. if self._wrapped is None: self._setup()
C:\Python27\lib\site-packages\django\utils\functional.py in __getattr__
  275. if self._wrapped is None:
... (this is the infinite loop) ...
C:\Python27\lib\site-packages\django\utils\functional.py in __getattr__
  275. if self._wrapped is None:

@blaze33

Same issue on django 1.4.2
For anyone interested in using pycallgraph to profile a django app, I did some debugging and solved this.
Add the following:

_wrapped = None

there: https://github.com/django/django/blob/1.4.2/django/utils/functional.py#L195

I'll make a pull request upstream once I get some time to write tests, explain this, etc.

@aaugustin

This bug will be fixed in Django 1.6.

@gak
Owner
gak commented

OK great. Closing.

@gak gak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.