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(asgi): Fix KeyError if transaction does not exist #4095

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

kevinji
Copy link
Contributor

@kevinji kevinji commented Feb 24, 2025

When "transaction" does not exist on the event, it will raise KeyError: "transaction". Ensure that this code handles "transaction" and "transaction_info" gracefully.


Thank you for contributing to sentry-python! Please add tests to validate your changes, and lint your code using tox -e linters.

Running the test suite on your PR might require maintainer approval. The AWS Lambda tests additionally require a maintainer to add a special label, and they will fail until this label is added.

@kevinji kevinji changed the title fix(asgi): fix KeyError if transaction does not exist fix(asgi): Fix KeyError if transaction does not exist Feb 24, 2025
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Hey @kevinji, thank you for the contribution!

Added a suggestion, please take a look.

Also, can you tell me when you observe this KeyError? What's your setup like? Wondering what cases there are where there is no transaction on the event and if that's not something we should fix.

@sentrivana sentrivana self-assigned this Feb 25, 2025
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.55%. Comparing base (189e4a9) to head (1a1c628).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4095   +/-   ##
=======================================
  Coverage   79.55%   79.55%           
=======================================
  Files         140      140           
  Lines       15521    15523    +2     
  Branches     2631     2631           
=======================================
+ Hits        12347    12349    +2     
  Misses       2338     2338           
  Partials      836      836           
Files with missing lines Coverage Δ
sentry_sdk/integrations/asgi.py 85.81% <100.00%> (+0.20%) ⬆️

... and 2 files with indirect coverage changes

@kevinji
Copy link
Contributor Author

kevinji commented Feb 26, 2025

We have a Starlette app which is running into this exception when fastapi_integrations is set to True.

Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Thanks for reworking, two more small suggestions and then we are good to merge

@sentrivana sentrivana added the Trigger: tests using secrets PR code is safe; run CI label Feb 26, 2025
@sentrivana sentrivana merged commit 5d26201 into getsentry:master Feb 26, 2025
143 of 145 checks passed
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.

2 participants