Skip to content

fix: prevent duplicate fuel code expiry notification emails#4154

Merged
AlexZorkin merged 1 commit intorelease-v1.2.9from
fix/fuel-code-expiry-duplicate-emails
Mar 27, 2026
Merged

fix: prevent duplicate fuel code expiry notification emails#4154
AlexZorkin merged 1 commit intorelease-v1.2.9from
fix/fuel-code-expiry-duplicate-emails

Conversation

@AlexZorkin
Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: The scheduler's db session runs outside the FastAPI request lifecycle (no auto-commit). mark_fuel_codes_notified() updated expiry_notification_sent_at but the change was never committed, so every daily cron run re-selected the same fuel codes and re-sent emails.
  • Added explicit db_session.commit() after marking codes as notified
  • Fixed get_expiring_fuel_codes query to use explicit .join() on FuelCodeStatus instead of joinedload for the WHERE filter (prevents potential cartesian product)
  • Updated tests to verify commit behavior

Closes #4131

Test plan

  • Verify no duplicate emails are sent for the same fuel code across consecutive scheduler runs
  • Verify expiry_notification_sent_at is persisted in the database after notifications are sent
  • Verify fuel codes with existing expiry_notification_sent_at are excluded from subsequent runs
  • Run existing unit tests

The scheduler runs outside the FastAPI request lifecycle, so its
db session has no auto-commit. mark_fuel_codes_notified() updated
expiry_notification_sent_at but the change was never committed,
causing every daily run to re-select and re-email the same codes.

- Add explicit db_session.commit() after marking codes as notified
- Fix get_expiring_fuel_codes query to use explicit join on
  FuelCodeStatus instead of joinedload for the WHERE filter
- Update tests to verify commit behavior
@AlexZorkin AlexZorkin requested a review from prv-proton March 26, 2026 22:51
@github-actions
Copy link
Copy Markdown

Backend Test Results

1 798 tests  ±0   1 797 ✅ ±0   14m 10s ⏱️ +3s
   45 suites ±0       1 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit a30b57a. ± Comparison against base commit 518ca5d.

@github-actions
Copy link
Copy Markdown

Frontend Test Results

    1 files  ±0    312 suites  ±0   3m 26s ⏱️ +3s
5 208 tests ±0  5 190 ✅ ±0  18 💤 ±0  0 ❌ ±0 
5 218 runs  ±0  5 200 ✅ ±0  18 💤 ±0  0 ❌ ±0 

Results for commit a30b57a. ± Comparison against base commit 518ca5d.

Copy link
Copy Markdown
Collaborator

@prv-proton prv-proton left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@AlexZorkin AlexZorkin merged commit bfa4b6f into release-v1.2.9 Mar 27, 2026
85 checks passed
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