@davoodmehraban89 / Aram-2 Mirror · read-only / commits / 0fa921a
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 3, 18:15 UTC

fix(mapping): preserve SQLite outer rollback and keep archive safety error

davoodmehraban89 committed Oct 23, 2026 at 02:44 UTC 0fa921aa5e2cdce7150eb2c3a679022bea692c70
1 file changed +9
backend/src/aram_backend/mapping_excel.py
+9
@@ -40,6 +40,8 @@ def _safe_archive(content: bytes) -> None:
40 raise MappingValidationError("XLSX archive exceeds safety limits")
41 if any(i.flag_bits & 0x1 for i in infos):
42 raise MappingValidationError("Encrypted XLSX entries are not supported")
43 + except MappingValidationError:
44 + raise
45 except (BadZipFile, ValueError) as exc:
46 raise MappingValidationError("Invalid XLSX archive") from exc
47
@@ -139,6 +141,13 @@ def export_mapping_workbook(entries: tuple[MappingEntry, ...]) -> bytes:
141 def import_mapping_workbook(session: Session, *, year_id: int, content: bytes) -> int:
142 """Stage all valid mappings atomically, without committing the caller's transaction."""
143 entries = preview_mapping_workbook(content)
144 + # SQLite's legacy transaction mode does not issue a real BEGIN for a SAVEPOINT.
145 + # Without an outer BEGIN, releasing the savepoint can persist rows despite
146 + # session.rollback(). Start the physical transaction explicitly when absent.
147 + if session.get_bind().dialect.name == "sqlite":
148 + connection = session.connection()
149 + if not connection.connection.driver_connection.in_transaction:
150 + connection.exec_driver_sql("BEGIN")
151 with session.begin_nested():
152 for entry in entries:
153 save_mapping_rule(