Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#19456 closed Bug (fixed)

SimpleLazyObject raises RuntimeError if __class__ accessed while tracing execution

Reported by: rouyrre+django@… Owned by: nobody
Component: Utilities Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I found the issue while trying to profile a django application with pycallgraph. The issue is referenced there:

The issue is reproduced with the following code:

import sys
from django.utils.functional import SimpleLazyObject

def tracer(frame, event, arg):

SimpleLazyObject(lambda x: x)

I wrote a failing test in tests/regressiontests/utils/ The issue is solved by defining _wrapped=None in the LazyObject class in django/utils/ and this does not seems to break anything, all tests still pass.

Do you prefer one commit for test + fix as it's a small issue or separate commits? Is the test written in the right place?

I can make a pull request once this ticket is created (as the commit guidelines specify I need a ticket number in the first place to commit & reference my code). Thanks for any comment about the issue or how to proceed.

Change History (7)

comment:2 Changed 6 years ago by Russell Keith-Magee

Triage Stage: UnreviewedReady for checkin
Type: UncategorizedBug

One commit for test + fix is fine.

comment:3 Changed 5 years ago by anonymous

comment:4 Changed 5 years ago by Aymeric Augustin

Component: UncategorizedUtilities

comment:5 Changed 5 years ago by Aymeric Augustin

The test should:

  • either restore the existing trace function if there is one rather than disable it,
  • or not run at all when a trace functions is active.

Otherwise this looks good.

comment:6 Changed 5 years ago by Aymeric Augustin <aymeric.augustin@…>

Resolution: fixed
Status: newclosed

In 9dc5702932a0031bc4fb5473f2cdccffc61dbe30:

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

Thanks blaze33 for the patch.

comment:7 Changed 5 years ago by anonymous

Good catch about restoring the trace function!
Thanks for the merge.

Note: See TracTickets for help on using tickets.
Back to Top