Doesn't work with Django's SimpleLazyObject #92

valtron opened this Issue Mar 23, 2012 · 4 comments


None yet
4 participants

valtron commented Mar 23, 2012

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

Line 235 of, 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\ in auth
  57. 'user': SimpleLazyObject(get_user),
C:\Python27\lib\site-packages\django\utils\ in init
  316. def init(self, func):
C:\Python27\lib\site-packages\ in tracer
  235. class_name = frame.f_locals['self']
C:\Python27\lib\site-packages\django\utils\ in __get_class
  354. if self._wrapped is None: self._setup()
C:\Python27\lib\site-packages\django\utils\ in getattr
  275. if self._wrapped is None:
... (this is the infinite loop) ...
C:\Python27\lib\site-packages\django\utils\ in getattr
  275. if self._wrapped is None:

blaze33 commented Nov 27, 2012

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


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

This bug will be fixed in Django 1.6.


gak commented Jun 2, 2013

OK great. Closing.

gak closed this Jun 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment