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
Format frame locals when captured #1744
Conversation
Before this commit, if ENABLE_STACKTRACES_LOCALS was True, each stack frame's locals dict would be stored directly in the captured stack trace, and only converted to a string once the stack trace was rendered. This means that for panels, such as the SQL Panel, which do not render the stack traces until later after they have all been captured, it is quite possible that the values in the locals dicts at the point when the stack trace was rendered would no longer be the same as they were at the time when the stack trace was captured, resulting in incorrect values being displayed to the user. Fix by converting the locals dict to a string immediately when it is captured (in the get_stack_trace() function as well as in the deprecated tidy_stacktrace() function) instead of in the render_stacktrace() function.
55d6866
to
17bf31d
Compare
The concern here is would this recording evaluate anything in the stack, such as a generator or callable that would then prevent the application (not the toolbar) from operating as expected? |
I don't expect so. The new code is using the exact same mechanism to convert to a string ( |
Also, the Cache panel actually does exactly this right now, because it calls |
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.
Makes sense.
will be converted to strings when the stack trace is captured rather when it | ||
is rendered, so that the correct values will be displayed in the rendered | ||
stack trace, as they may have changed between the time the stack trace was | ||
captured and when it is rendered. |
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.
Thank you for the well written changelog @living180!
Before this commit, if
ENABLE_STACKTRACES_LOCALS
wasTrue
, each stack frame's locals dict would be stored directly in the captured stack trace, and only converted to a string once the stack trace was rendered. This means that for panels, such as the SQL Panel, which do not render the stack traces until later after they have all been captured, it is quite possible that the values in the locals dicts at the point when the stack trace was rendered would no longer be the same as they were at the time when the stack trace was captured, resulting in incorrect values being displayed to the user.Fix by converting the locals dict to a string immediately when it is captured (in the
get_stack_trace()
function as well as in the deprecatedtidy_stacktrace()
function) instead of in therender_stacktrace()
function.I realize that this represents an internal API change, as now the last item of the tuples returned by
get_stack_trace()
will now be a string rather than a dict. However, this is not actually a documented public API and I do not expect any third-party panels to be trying to inspect or use the locals dicts from the stack traces directly, even if they are usingget_stack_trace()
(or more likely,get_stack()
andtidy_stacktrace()
). But if there are concerns about this, I have some thoughts about possible ways to address it.