#19456 closed Bug (fixed)
SimpleLazyObject raises RuntimeError if __class__ accessed while tracing execution
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Utilities | Version: | dev |
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 |
Description
I found the issue while trying to profile a django application with pycallgraph. The issue is referenced there: https://github.com/gak/pycallgraph/issues/92
The issue is reproduced with the following code:
import sys from django.utils.functional import SimpleLazyObject def tracer(frame, event, arg): frame.f_locals['self'].__class__ sys.settrace(tracer) SimpleLazyObject(lambda x: x) sys.settrace(None)
I wrote a failing test in tests/regressiontests/utils/functional.py. The issue is solved by defining _wrapped=None in the LazyObject class in django/utils/functional.py 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:1 by , 12 years ago
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|---|
Type: | Uncategorized → Bug |
One commit for test + fix is fine.
comment:3 by , 12 years ago
Code was updated as discussed with @spookylukey
https://github.com/blaze33/django/commit/2f6d887bd0a110e3a662ac1d056d6cdabf38632b
comment:4 by , 12 years ago
Component: | Uncategorized → Utilities |
---|
comment:5 by , 12 years ago
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 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I commited the code there: https://github.com/blaze33/django/commit/772f4b0f357b34abd1041d99b990f4f5b88bed6e