Skip to content

fix: use SQLAlchemy session in ta_processor instead of Django ORM - #2572

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-ta-processor-sqlalchemy-session
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-ta-processor-sqlalchemy-session

Conversation

@sentry

@sentry sentry Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem: In the TestResultsProcessorTask, ta_processor() previously queried the database using the Django ORM (ReportSession.objects.using("default").get(...)). Because Django is configured with CONN_MAX_AGE=0 in the worker, every query initiates a new database connection directly resolving the pgbouncer hostname. In the worker-test-analytics pod's network namespace, DNS resolution for pgbouncer fails, triggering an unhandled psycopg2.OperationalError: could not translate host name "pgbouncer" to address: Name or service not known.

Fix

  • Plumbed db_session from TestResultsProcessorTask.run_impl into ta_processor().
  • Migrated ta_processor(), handle_file_not_found(), handle_parsing_error(), and get_ta_processing_info() from Django ORM models to the worker's native SQLAlchemy models (Upload, UploadError, Repository, Commit).
  • Uses SQLAlchemy's existing pooled database connection session, removing the per-task Django connection setup and resolving the DNS resolution failure.

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 WORKER-ZAT

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.


Note

Medium Risk
Touches upload state and error persistence on the test-results path; behavior should match prior Django writes but depends on the injected session being non-null when update_state=True.

Overview
Routes test-analytics upload processing through the worker’s SQLAlchemy session instead of Django ORM, so DB access reuses the task’s pooled connection rather than opening a new Django connection (which was failing DNS for pgbouncer in worker-test-analytics).

TestResultsProcessorTask now passes db_session into ta_processor(). Upload load/update, UploadError writes, and commit/repository lookups use SQLAlchemy models (Upload, UploadError, Commit, Repository) with query / add / flush instead of ReportSession and Django objects APIs. Error helpers resolve the session from the upload via get_db_session() when marking missing files or parse failures.

Reviewed by Cursor Bugbot for commit 92bfa82. Bugbot is set up for automated code reviews on this repo. Configure here.

@sentry

sentry Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Sentry needs additional GitHub App permissions

The Sentry GitHub App installation for this repository is missing permissions it needs to keep iterating on this pull request to get CI passing.

Review and accept the updated permissions to let Seer continue: https://github.com/organizations/codecov/settings/installations/86101127/permissions/update

This branch has not been deployed

No deployments
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