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(spotlight): More defensive Django spotlight middleware injection #3665

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

BYK
Copy link
Member

@BYK BYK commented Oct 16, 2024

Turns out settings.MIDDLEWARE does not have to be a list. This causes issues as not all iterables support appending items to them. This PR leverages itertools.chain along with type(settings.MIDDLEWARE) to extend the middleware list while keeping its original type. It also adds a try-except block around the injection code to make sure it doesn't block anything further down in the unexpected case that it fails.

Turns out `settings.MIDDLEWARE` does not have to be a `list`. This causes issues as not all iterables support appending items to them. This PR leverages `itertools.chain` along with `type(settings.MIDDLEWARE)` to extend the middleware list while keeping its original type. It also adds a try-except block around the injection code to make sure it doesn't block anything further down in the unexpected case that it fails.
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.31%. Comparing base (f493057) to head (674ca35).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/spotlight.py 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3665      +/-   ##
==========================================
- Coverage   84.32%   84.31%   -0.01%     
==========================================
  Files         133      133              
  Lines       14063    14068       +5     
  Branches     2379     2380       +1     
==========================================
+ Hits        11858    11861       +3     
  Misses       1471     1471              
- Partials      734      736       +2     
Files with missing lines Coverage Δ
sentry_sdk/spotlight.py 66.66% <87.50%> (+1.09%) ⬆️

... and 1 file with indirect coverage changes

sentry_sdk/spotlight.py Show resolved Hide resolved
sentry_sdk/spotlight.py Show resolved Hide resolved
@untitaker untitaker added the Trigger: tests using secrets PR code is safe; run CI label Oct 16, 2024
@sentrivana sentrivana enabled auto-merge (squash) October 17, 2024 07:18
@sentrivana sentrivana merged commit 891afee into getsentry:master Oct 17, 2024
137 of 139 checks passed
@BYK BYK deleted the byk/fix/tuple-protect branch October 17, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Trigger: tests using secrets PR code is safe; run CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants