fix(06.2): WR-08 delete_document defers commit so audit log writes in same transaction
This commit is contained in:
@@ -140,7 +140,12 @@ async def list_metadata(
|
||||
return rows
|
||||
|
||||
|
||||
async def delete_document(session: AsyncSession, doc_id: str, skip_quota: bool = False) -> bool:
|
||||
async def delete_document(
|
||||
session: AsyncSession,
|
||||
doc_id: str,
|
||||
skip_quota: bool = False,
|
||||
auto_commit: bool = True,
|
||||
) -> bool:
|
||||
"""Delete a document's MinIO object and its PostgreSQL row.
|
||||
|
||||
Returns False if the document is not found; True on success.
|
||||
@@ -149,6 +154,11 @@ async def delete_document(session: AsyncSession, doc_id: str, skip_quota: bool =
|
||||
|
||||
skip_quota=True skips the quota decrement — used for cloud-stored documents
|
||||
that were never charged against the user's MinIO quota (T-06.2-03-01).
|
||||
|
||||
auto_commit=False defers the session.commit() to the caller, allowing the
|
||||
caller to write an audit log entry in the same transaction before committing
|
||||
(avoids the split-transaction gap where a failed audit write loses the record
|
||||
while the document row is already gone).
|
||||
"""
|
||||
try:
|
||||
uid = uuid.UUID(doc_id)
|
||||
@@ -179,7 +189,8 @@ async def delete_document(session: AsyncSession, doc_id: str, skip_quota: bool =
|
||||
)
|
||||
|
||||
await session.delete(doc)
|
||||
await session.commit()
|
||||
if auto_commit:
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user