fix(Sentry:PYDOTORG-PROD-1MQ): duplicate key crash on sponsor appliction form submission#2962
Conversation
…tion form submission
There was a problem hiding this comment.
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
IntegrityErrorwhen 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.
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>
There was a problem hiding this comment.
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 handleIntegrityErrorby 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.
Description