Merge pull request 'Auto-commit local changes before build (2026-01-08 11:15:47)' (#61) from v20260108-26-mail-move-only-after-successful-import into main

Reviewed-on: #61
This commit is contained in:
Ivo Oskamp 2026-01-13 11:23:53 +01:00
commit d5eecd9220
3 changed files with 37 additions and 1 deletions

View File

@ -1 +1 @@
v20260108-26-changelog-0.1.18-update
v20260108-26-mail-move-only-after-successful-import

View File

@ -436,6 +436,21 @@ def run_auto_import(settings: SystemSettings):
new_messages = 0
auto_approved = 0
auto_approved_runs = []
# Never move messages when the import failed (prevents "moved but not stored" situations).
processed_folder_id = None
# Ensure imported messages are committed before moving them to another folder.
# If commit fails, do not move anything.
if processed_folder_id and new_messages >= 0:
try:
db.session.commit()
except Exception as exc:
db.session.rollback()
errors.append(f"Failed to commit imported messages: {exc}")
new_messages = 0
auto_approved = 0
auto_approved_runs = []
processed_folder_id = None
# Move messages to the processed folder if configured
if processed_folder_id:
@ -613,6 +628,21 @@ def run_manual_import(settings: SystemSettings, batch_size: int):
errors.append(str(exc))
new_messages = 0
auto_approved_runs = []
# Never move messages when the import failed (prevents "moved but not stored" situations).
processed_folder_id = None
# Ensure imported messages are committed before moving them to another folder.
# If commit fails, do not move anything.
if processed_folder_id and new_messages >= 0:
try:
db.session.commit()
except Exception as exc:
db.session.rollback()
errors.append(f"Failed to commit imported messages: {exc}")
new_messages = 0
auto_approved = 0
auto_approved_runs = []
processed_folder_id = None
# Move messages to the processed folder if configured
if processed_folder_id:

View File

@ -1,3 +1,9 @@
## v20260108-26-mail-move-only-after-successful-import
- Changed mail import flow so messages are only moved to the processed folder after a successful database store and commit.
- Prevented Graph mails from being moved when parsing, storing, or committing to the database fails.
- Added explicit commit and rollback handling to ensure database integrity before mail state changes.
- Improved logging around import and commit failures to better trace skipped or retried mails.