feat: persist issued document artifacts and invalidate draft artifacts on edit

This commit is contained in:
Арсентьев Александр
2026-09-29 18:17:36 +03:00
parent 1917bc6513
commit c1be111e1a
6 changed files with 1181 additions and 0 deletions
+28
View File
@@ -362,3 +362,31 @@ def invalidate_artifacts(
stmt = stmt.where(DocumentArtifact.format == _validate_segment(format, "format"))
result = db.execute(stmt)
return int(result.rowcount or 0)
# ---------------------------------------------------------------------------
# Cleanup helper (for failed transactions)
# ---------------------------------------------------------------------------
def remove_artifact_file(artifact: DocumentArtifact) -> bool:
"""
Delete the physical file of a single artifact row.
Narrowly scoped cleanup for a failed transaction that created an artifact
file but could not commit. Accepts only a DocumentArtifact row (never an
arbitrary path). Resolves through the safe path resolver. Never touches
other artifacts. Returns True if a file was removed.
"""
if artifact is None or not artifact.storage_key:
return False
try:
path = resolve_storage_path(artifact.storage_key)
except ArtifactPathError:
return False
try:
if path.is_file():
path.unlink()
return True
except OSError:
return False
return False