Fix: avoid unnecessary creating new PDF with pw removal workflow (#12948)

This commit is contained in:
shamoon
2026-06-07 13:30:08 -07:00
committed by GitHub
parent eb292baa69
commit 6f8e39c2e0
2 changed files with 130 additions and 9 deletions
+13
View File
@@ -904,6 +904,19 @@ def remove_password(
doc.id,
pair.source_doc.source_path,
)
try:
with pikepdf.open(source_path) as pdf:
if not pdf.is_encrypted:
logger.info(
"Skipping password removal for document %s because the "
"source PDF is not encrypted",
pair.root_doc.id,
)
continue
except pikepdf.PasswordError:
# Password-protected PDFs need the supplied password below.
pass
with pikepdf.open(source_path, password=password) as pdf:
filepath: Path = (
Path(tempfile.mkdtemp(dir=settings.SCRATCH_DIR))