feat: persist issued document artifacts and invalidate draft artifacts on edit
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user