fix: prevent duplicate fuel code expiry notification emails#4154
Merged
AlexZorkin merged 1 commit intorelease-v1.2.9from Mar 27, 2026
Merged
fix: prevent duplicate fuel code expiry notification emails#4154AlexZorkin merged 1 commit intorelease-v1.2.9from
AlexZorkin merged 1 commit intorelease-v1.2.9from
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mark_fuel_codes_notified()updatedexpiry_notification_sent_atbut the change was never committed, so every daily cron run re-selected the same fuel codes and re-sent emails.db_session.commit()after marking codes as notifiedget_expiring_fuel_codesquery to use explicit.join()onFuelCodeStatusinstead ofjoinedloadfor the WHERE filter (prevents potential cartesian product)Closes #4131
Test plan
expiry_notification_sent_atis persisted in the database after notifications are sentexpiry_notification_sent_atare excluded from subsequent runs