Skip to content
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

fix(profiling): Use type() instead when extracting frames #3716

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

Zylphrex
Copy link
Member

@Zylphrex Zylphrex commented Oct 29, 2024

When extract frame names, we should avoid accessing the __class__ attribute as it can be overwritten in the class implementation. In this particular instance, the SimpleLazyObject class in django wraps __class__ so when it is accessed, it can cause the underlying lazy object to be evaluation unexpectedly. To avoid this, use the type() builtin function which cannot be overwritten and will return the correct class.

Note that this does not work with old style classes but since dropping python 2 support, we only need to consider new style classes.

When extract frame names, we should avoid accessing the `__class__` attribute as
it can be overwritten in the class implementation. In this particular instance,
the `SimpleLazyObject` class in django wraps `__class__` so when it is accessed,
it can cause the underlying lazy object to be evaluation unexpectedly. To avoid
this, use the `type()` builtin function which does cannot be overwritten and
will return the correct class.

Note that this does not work with old style classes but since dropping python 2
support, we only need to consider new style classes.
@Zylphrex Zylphrex force-pushed the txiao/fix/use-type-instead-when-extracting-frames branch from 6597c19 to 95303b5 Compare October 29, 2024 16:35
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.28%. Comparing base (4c1367b) to head (95303b5).
Report is 6 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3716      +/-   ##
==========================================
- Coverage   84.28%   83.28%   -1.00%     
==========================================
  Files         133      133              
  Lines       14257    14432     +175     
  Branches     2405     2457      +52     
==========================================
+ Hits        12016    12020       +4     
- Misses       1490     1662     +172     
+ Partials      751      750       -1     
Files with missing lines Coverage Δ
sentry_sdk/profiler/utils.py 88.88% <100.00%> (ø)

... and 1 file with indirect coverage changes

@Zylphrex Zylphrex merged commit 02d0934 into master Oct 29, 2024
136 checks passed
@Zylphrex Zylphrex deleted the txiao/fix/use-type-instead-when-extracting-frames branch October 29, 2024 17:14
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