Skip to content

Tweak get_stack_trace() API #1637

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

Merged
merged 3 commits into from
Jun 1, 2022
Merged

Conversation

living180
Copy link
Contributor

Replace the depth argument to get_stack_trace() with a more intuitive skip argument. Update the cache and SQL panels to supply a skip argument to get_stack_trace() to ensure that the stack traces are clean even when HIDE_IN_STACKTRACES is empty.

@matthiask
Copy link
Member

I'm not completely sure if skip is clearer than depth. Maybe skip_stack_levels but in this case we could copy the stacklevel name from warnings.warn?

@living180
Copy link
Contributor Author

How about skip_frames? I don't want to copy stacklevel because my skip argument has slightly different semantics. stacklevel from warnings.warn() and depth from sys._getframe() both default to 1, and the reference point is from the frame of warnings.warn() or sys._getframe(). But the caller doesn't care about the frames of the functions it is calling to get the trace. It wants either a trace starting with itself, or a lower frame if it (or possibly one or more of its callers) shouldn't be displayed to the user. That's why I switched to a default value of 0 for skip. When I first added the depth argument to the get_stack_trace() calls for the cache and SQL panels, it was depth=3, which felt confusing and I really had to think about it, and that was right when I was writing the code (not coming back and trying to understand it weeks or months later). Now with skip=2, the meaning seems clear to me: skip the current frame (which calls get_stack_trace()) plus one more frame (the caller of the current frame).

Does this make sense?

Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

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

Yes, makes sense. Thanks for the explanation!

I think the change is fine as-is.

living180 added 2 commits June 1, 2022 16:16
Rename the `depth` argument to `skip` and change the semantics so that
now `skip=0` has the same meaning as `depth=1`.
Ensure that stack traces do not include any of the cache or SQL panel
tracking infrastructure even if HIDE_IN_STACKTRACES is empty.
@matthiask matthiask merged commit e59a8ec into django-commons:main Jun 1, 2022
@living180 living180 deleted the stack_trace_api branch June 2, 2022 11:55
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.

2 participants