Skip to content

fix(compose_notifications): use ON CONFLICT DO NOTHING to prevent UnqueViolation#921

Merged
volodkindv merged 1 commit into
cherrytea-dev:mainfrom
volodkindv:feature/fix-notif-duplicate-violation
Jul 10, 2026
Merged

fix(compose_notifications): use ON CONFLICT DO NOTHING to prevent UnqueViolation#921
volodkindv merged 1 commit into
cherrytea-dev:mainfrom
volodkindv:feature/fix-notif-duplicate-violation

Conversation

@volodkindv

Copy link
Copy Markdown
Collaborator

batch_insert_notifications now uses INSERT ... ON CONFLICT DO NOTHING on the partial unique index notif_by_user_unique_unsent_idx. This atomically skips duplicate records that arise from:

  • YMQ redelivery of compose_notifications pub/sub messages
  • Race conditions when call_self_if_need_compose_more re-triggers before the current change_log is marked 'y'

Previously, flush_batch had DOUBLING_DIAG checks that only logged warnings but still attempted the insert, causing 502 errors on production (IntegrityError crash in compose_notifications).

Also replaced the per-record diagnostic queries with a single inserted-vs-skipped log message, reducing N queries per batch to 1.

Fixes the 502 errors observed for resource_id d4edldufbefp11r92d94.

…queViolation

batch_insert_notifications now uses INSERT ... ON CONFLICT DO NOTHING
on the partial unique index notif_by_user_unique_unsent_idx. This
atomically skips duplicate records that arise from:

- YMQ redelivery of compose_notifications pub/sub messages
- Race conditions when call_self_if_need_compose_more re-triggers
  before the current change_log is marked 'y'

Previously, flush_batch had DOUBLING_DIAG checks that only logged
warnings but still attempted the insert, causing 502 errors on
production (IntegrityError crash in compose_notifications).

Also replaced the per-record diagnostic queries with a single
inserted-vs-skipped log message, reducing N queries per batch to 1.

Fixes the 502 errors observed for resource_id d4edldufbefp11r92d94.
@volodkindv volodkindv merged commit cf93e90 into cherrytea-dev:main Jul 10, 2026
1 of 2 checks passed
@volodkindv volodkindv deleted the feature/fix-notif-duplicate-violation branch July 10, 2026 14:13
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.

1 participant