Skip to content

chore(launchpad): change size analysis upload logic to create/update size metrics table #94656

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

Conversation

NicoHinderling
Copy link
Contributor

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.

preprod_artifact.save(update_fields=["analysis_file_id", "state", "date_updated"])

# Get or create PreprodArtifactSizeMetrics record
size_metrics, created = PreprodArtifactSizeMetrics.objects.get_or_create(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an upsert method?

cursor[bot]

This comment was marked as outdated.

@NicoHinderling NicoHinderling force-pushed the 06-30-chore_launchpad_create_replacement_analysis_file_id_col_in_preprod_size_metrics_table branch from e421c6a to ca3696e Compare June 30, 2025 21:08
@NicoHinderling NicoHinderling force-pushed the 06-30-chore_launchpad_change_size_analysis_upload_logic_to_create_update_size_metrics_table branch from ec930e9 to 221dedf Compare June 30, 2025 21:08
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Base automatically changed from 06-30-chore_launchpad_create_replacement_analysis_file_id_col_in_preprod_size_metrics_table to master June 30, 2025 22:10
@NicoHinderling NicoHinderling force-pushed the 06-30-chore_launchpad_change_size_analysis_upload_logic_to_create_update_size_metrics_table branch from 011197c to fe84025 Compare June 30, 2025 22:19
cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Transaction Split Causes Artifact Inconsistency

The code now uses two separate transactions for updating the artifact state and creating/updating size metrics. This breaks atomicity, leading to an inconsistent state where a PreprodArtifact is marked PROCESSED but lacks corresponding size metrics if the second transaction fails. This can mislead downstream consumers. Additionally, the assembled file is not cleaned up upon failure of the second transaction, causing a resource leak. The original code maintained atomicity and ensured cleanup via a single transaction.

src/sentry/preprod/tasks.py#L218-L233

# Update artifact state in its own transaction with proper database routing
with transaction.atomic(router.db_for_write(PreprodArtifact)):
preprod_artifact.state = PreprodArtifact.ArtifactState.PROCESSED
preprod_artifact.save(update_fields=["state", "date_updated"])
# Update size metrics in its own transaction
with transaction.atomic(router.db_for_write(PreprodArtifactSizeMetrics)):
size_metrics, created = PreprodArtifactSizeMetrics.objects.update_or_create(
preprod_artifact=preprod_artifact,
defaults={
"analysis_file_id": assemble_result.bundle.id,
"metrics_artifact_type": PreprodArtifactSizeMetrics.MetricsArtifactType.MAIN_ARTIFACT, # TODO: parse this from the treemap json
"state": PreprodArtifactSizeMetrics.SizeAnalysisState.COMPLETED,
},
)

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

@NicoHinderling NicoHinderling merged commit a030b85 into master Jun 30, 2025
65 checks passed
@NicoHinderling NicoHinderling deleted the 06-30-chore_launchpad_change_size_analysis_upload_logic_to_create_update_size_metrics_table branch June 30, 2025 22:43
Copy link

sentry-io bot commented Jul 1, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎

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