fix(notifications): tryClaim drop @Modifying — unblocks ALL dispatch

This commit is contained in:
Александр Зимин
2026-05-15 16:02:11 +00:00
parent 1eed8be700
commit c41c561ee6
@@ -21,8 +21,17 @@ public interface NotificationLogRepository extends JpaRepository<NotificationLog
* (другой consumer уже claim'ил, или sweep job не освободил stuck row).
*
* <p>Используется в {@code IdempotencyGuard.shouldSend()}.
*
* <p><b>Без</b> {@code @Modifying} — native INSERT с RETURNING clause работает
* как SELECT-shaped query (returns 0..1 rows). {@code @Modifying} ограничивает
* return type до {@code void/int/Integer}, что несовместимо с {@code Optional<Long>}
* → Spring Data JPA throws InvalidDataAccessApiUsageException на каждом
* dispatcher tick. Bug history: {@code @Modifying} добавили cargo-cult'ом
* (INSERT ⇒ mutating), but native + RETURNING — read-shaped в JPA model.
* Эта misconfiguration блокировала весь dispatch pipeline — пока race
* не был fix'нут в MR !214, ошибка вообще не surface'илась (events не
* doходили до tryClaim).
*/
@Modifying
@Query(value = """
INSERT INTO notification_log (event_id, event_type, draft_id, channel, recipient, status, sent_at)
VALUES (:eventId, :eventType, :draftId, :channel, :recipient, 'PENDING', NOW())