-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't try to undo cache method monkey patching #1770
Conversation
Trying to undo the monkey patch of cache methods in the CachePanel.disable_instrumentation() method is fragile in the presence of other code which may also monkey patch the same methods (such as Sentry's Django integration), and there are theoretically situations where it is actually impossible to do correctly. Thus once a cache has been monkey-patched, leave it that way, and instead rely on checking in the patched methods to see if recording needs to happen. This is done via a _djdt_panel attribute which is set to the current panel in the enable_instrumentation() method and then set to None in the disable_instrumentation() method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea. I haven't tested it out, it would certainly be helpful if the change were tested by those who reported crashes in the other issue.
Sorry for the bikeshedding, but maybe _djdt_recording
was a more fitting name than _djdt_panel
; or maybe I misunderstand the intention of the variable?
I also think we should generally move towards using from time import perf_counter
instead of time.time()
to measure short durations; my understanding is that time.time
could be affected by updating the system clock. It's extremely unlikely to matter of course, but perf_counter
would be more correct. And it's also what Django does, see https://github.com/django/django/blob/1586a09b7949bbb7b0d84cb74ce1cadc25cbb355/django/test/utils.py#L934-L941
So the type of the variable actually changed: previously it was a |
Totally agree, though that is really orthogonal to this change. I can look at making a new PR switching to |
Ah of course, thank you! |
See django-commons/django-debug-toolbar#1770 We hit this while doing a deploy.
See django-commons/django-debug-toolbar#1770 We hit this while doing a deploy.
See django-commons/django-debug-toolbar#1770 We hit this while doing a deploy.
See django-commons/django-debug-toolbar#1770 We hit this while doing a deploy.
Description
Trying to undo the monkey patch of cache methods in the
CachePanel.disable_instrumentation()
method is fragile in the presence of other code which may also monkey patch the same methods (such as Sentry's Django integration), and there are theoretically situations where it is actually impossible to do correctly. Thus once a cache has been monkey-patched, leave it that way, and instead rely on checking in the patched methods to see if recording needs to happen. This is done via a_djdt_panel
attribute which is set to the current panel in theenable_instrumentation()
method and then set toNone
in thedisable_instrumentation()
method.Fixes #1769
Checklist:
docs/changes.rst
.