Skip to content

fix(timeseries): prevent duplicate dataset creation race condition - #1868

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/api-es8-dataset-race
Open

fix(timeseries): prevent duplicate dataset creation race condition#1868
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/api-es8-dataset-race

Conversation

@sentry

@sentry sentry Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the GraphQLError: duplicate key value violates unique constraint "name_repository_id_unique" (API-ES8).

Problem:
When multiple concurrent GraphQL requests, specifically GetReposCoverageMeasurements, attempt to fetch coverage measurements for an owner, a race condition can occur. The owner_coverage_measurements_with_fallback function identifies timeseries_dataset entries that are missing for certain repositories and then attempts to create them using Dataset.objects.bulk_create.

Root Cause:
If two or more requests simultaneously identify the same set of missing datasets and proceed to bulk_create, the second (or subsequent) bulk_create operation will attempt to insert rows that already exist, leading to a UniqueViolation (IntegrityError) on the name_repository_id_unique constraint.

Solution:
Added ignore_conflicts=True to the Dataset.objects.bulk_create call in timeseries/helpers.py. This leverages PostgreSQL's ON CONFLICT DO NOTHING behavior, allowing concurrent inserts to proceed without error if a row with the same unique key already exists. This effectively resolves the race condition.

Impact on trigger_backfill:
Confirmed that trigger_backfill gracefully handles an empty list of created_datasets (which can occur if all datasets were created by a racing process and ignore_conflicts=True was used), ensuring no further issues.

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this 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 Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes API-ES8

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.

0 participants