Skip to content

fix(spotlight): More defensive Django spotlight middleware injection#3665

Merged
sentrivana merged 3 commits into
getsentry:masterfrom
BYK:byk/fix/tuple-protect
Oct 17, 2024
Merged

fix(spotlight): More defensive Django spotlight middleware injection#3665
sentrivana merged 3 commits into
getsentry:masterfrom
BYK:byk/fix/tuple-protect

Conversation

@BYK

@BYK BYK commented Oct 16, 2024

Copy link
Copy Markdown
Member

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.
@codecov

codecov Bot commented Oct 16, 2024

Copy link
Copy Markdown

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

Comment thread sentry_sdk/spotlight.py
Comment thread sentry_sdk/spotlight.py
@sentrivana
sentrivana enabled auto-merge (squash) October 17, 2024 07:18
@sentrivana
sentrivana merged commit 891afee into getsentry:master Oct 17, 2024
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants