Skip to content

fix(Sentry:PYDOTORG-PROD-1MQ): duplicate key crash on sponsor appliction form submission#2962

Merged
JacobCoffee merged 3 commits intomainfrom
fix/sponsor-asset-integrity-error
Mar 13, 2026
Merged

fix(Sentry:PYDOTORG-PROD-1MQ): duplicate key crash on sponsor appliction form submission#2962
JacobCoffee merged 3 commits intomainfrom
fix/sponsor-asset-integrity-error

Conversation

@JacobCoffee
Copy link
Member

Copilot AI review requested due to automatic review settings March 13, 2026 17:27
Copy link
Member Author

@JacobCoffee JacobCoffee left a comment

Choose a reason for hiding this comment

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

need s test

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Prevents production crashes during sponsor application form submission by making generic asset creation resilient to concurrent inserts (duplicate key/unique constraint collisions) in the sponsors benefits configuration flow.

Changes:

  • Wrap generic asset creation in a DB transaction and handle IntegrityError when a concurrent request has already created the same asset.
  • Update Django DB imports to support transaction/exception handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

JacobCoffee and others added 2 commits March 13, 2026 12:30
Covers the case where a sponsor already has a GenericAsset with the
same internal_name from a prior application, ensuring create_benefit_feature
does not crash on duplicate key.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Only swallow the IntegrityError if the asset now exists (the expected
duplicate-key case). Unrelated integrity violations are re-raised so
they surface properly. Adds test coverage for the re-raise path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 13, 2026 17:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a production Sentry error caused by a duplicate key IntegrityError when creating sponsor/sponsorship “asset” records during benefit feature creation (notably during sponsorship application submission).

Changes:

  • Wrap asset creation in a savepoint (transaction.atomic()) and handle IntegrityError by re-checking for an already-created asset to avoid crashing on duplicate insert races.
  • Add tests intended to prevent regressions and ensure non-duplicate IntegrityErrors still propagate.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/sponsors/models/benefits.py Adds atomic/savepoint + IntegrityError handling around generic asset creation in AssetConfigurationMixin.create_benefit_feature().
apps/sponsors/tests/test_models.py Adds regression tests around preexisting assets and IntegrityError propagation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JacobCoffee JacobCoffee merged commit d2d0128 into main Mar 13, 2026
18 checks passed
@JacobCoffee JacobCoffee deleted the fix/sponsor-asset-integrity-error branch March 13, 2026 18:03
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.

2 participants