Skip to content

Enable showing stacktraces locals - #1203

Closed
jperelli wants to merge 10 commits into
django-commons:masterfrom
jperelli:add_stacktraces_locals
Closed

Enable showing stacktraces locals#1203
jperelli wants to merge 10 commits into
django-commons:masterfrom
jperelli:add_stacktraces_locals

Conversation

@jperelli

Copy link
Copy Markdown
Contributor

Hi! I added a config variable to be able to see the locals inside the stacktraces.

The motivation for this was to be able to find duplicated queries by having more context. In my case this helped debugging django-rest-framework query duplication, see the pic below.

image

I had no clue why the queries were being duplicated, but with local()s I'm able now to see that it's in a Matchexception model and when trying to get the feetype attribute. After this, it was an easy fix.

I added the configuration as disabled by default because it is too verbose for most cases, but it is very useful for when issues are getting difficult to spot, enable it one time, fix the issue and disable it again.

@jperelli
jperelli force-pushed the add_stacktraces_locals branch from fe55ef9 to 425f30d Compare October 17, 2019 15:01
@jperelli
jperelli force-pushed the add_stacktraces_locals branch from 425f30d to 7ce3b45 Compare October 17, 2019 15:02
@tim-schilling

Copy link
Copy Markdown
Member

I like the idea, though I think it might be worth to format the dict in the template. Otherwise as you mentioned, it will likely be noisy and difficult to read. What do you think?

@jperelli

jperelli commented Nov 25, 2019

Copy link
Copy Markdown
Contributor Author

I agree. Sent a commit to improve it.

In order to not try to parse locals() to avoid break anything (and support nested structures), I opted to use the standard pprint and style it a little better with some css. Also refactored to take a 'template string' out into its own template. This is the best I could do

image

@tim-schilling tim-schilling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be reviewed by a more involved contributor before it can be merged. Another concern is that the locals could expose sensitive information. While this isn't such a big deal while running this locally, it could be problematic if it were run on a production server and/or a server that's not running https. Maybe including this in a caution segment in the docs would suffice?

However, this should also include tests for the locals being included for both the sql and cache panels.

Comment thread debug_toolbar/utils.py Outdated
Comment thread debug_toolbar/templates/debug_toolbar/stacktrace.html Outdated
@tim-schilling

Copy link
Copy Markdown
Member

@matthiask What's your opinion of this idea?

@matthiask

Copy link
Copy Markdown
Member

@tim-schilling This would surely have helped me at times too. I always revert to print() debugging in this case, but builtin support for this would be nice.

@jperelli

Copy link
Copy Markdown
Contributor Author

Hi @tim-schilling I added your commits, fixed an issue and added some tests (not sure if they are enough). Let me know what you think

@tim-schilling tim-schilling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I'm going to rebase on upstream/master, squash the commits and merge it to master. Thanks @jperelli for the PR!

@tim-schilling

Copy link
Copy Markdown
Member

Merged with fd50ce3

@jperelli

Copy link
Copy Markdown
Contributor Author

Thank you! Can't wait to see it live :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants