Skip to content

fix(eap): Add defensive null-safety for contexts extraction in producer#110866

Draft
cursor[bot] wants to merge 1 commit intomasterfrom
cursor/eap-producer-null-safety-2e8c
Draft

fix(eap): Add defensive null-safety for contexts extraction in producer#110866
cursor[bot] wants to merge 1 commit intomasterfrom
cursor/eap-producer-null-safety-2e8c

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor bot commented Mar 17, 2026

Problem

When processing events with invalid contexts field values, the produce_processing_errors_to_eap function would crash with an AttributeError because event.data.get('contexts') can return None (when the key exists but has an invalid value that was stripped during validation), and the code attempted to chain .get() calls on None.

Solution

Added defensive null-safety using the or {} fallback pattern to handle cases where event_data fields may be None due to upstream validation failures or corruption.

Changes:

  • Updated trace_id extraction to use (event_data.get("contexts") or {}) pattern
  • Added inline comment explaining why defensive null-checks are necessary
  • Added test coverage for contexts=None case
  • Added test coverage for sdk=None case to verify existing defensive handling

Testing

All existing tests pass, plus two new tests:

  • test_skips_when_contexts_is_none: Verifies graceful handling when contexts is None
  • test_handles_none_sdk_gracefully: Verifies sdk=None is handled correctly

Fixes SENTRY-5KRQ

Open in Web Open in Cursor 

Fixes SENTRY-5KRQ

Add defensive null-safety to trace_id extraction in produce_processing_errors_to_eap
function to handle cases where event_data fields may be None due to upstream validation
failures or corruption.

- Update trace_id extraction to use 'or {}' fallback pattern when contexts is None
- Add inline comment explaining why defensive null-checks are necessary
- Add test coverage for contexts=None case
- Add test coverage for sdk=None case to verify existing defensive handling

The issue occurred when event.data.get('contexts') returned None (instead of missing key)
due to the contexts field being invalid and stripped during validation, causing chained
.get() calls to fail.

Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 17, 2026
@getsantry
Copy link
Copy Markdown
Contributor

getsantry bot commented Apr 8, 2026

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant