Skip to content

Conversation

@seer-by-sentry
Copy link
Contributor

This PR addresses issue SENTRY-434K, where Environment.DoesNotExist errors occurred during the link_event_to_user_report pipeline step in sentry.issues.tasks.post_process.post_process_group.

The root cause was identified as event.get_environment() attempting to retrieve an Environment record with an empty string name (when an event lacked an explicit environment tag). If this default empty-string environment had never been implicitly created for a given organization, the .get() call would fail.

The solution modifies BaseEvent.get_environment() in src/sentry/services/eventstore/models.py. Instead of directly calling Environment.get_for_organization_id() which uses a .get() query, it now wraps this call in a try-except Environment.DoesNotExist block. If the environment does not exist, it falls back to Environment.objects.get_or_create(name=name, organization_id=organization_id), ensuring the default empty-string environment is created if it's missing. This makes the environment lookup more robust and prevents the DoesNotExist error.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 24, 2026
@cvxluo cvxluo self-assigned this Jan 24, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants