PaddlePaddle/PaddleOCR · warning · InvalidRequestError
Destination already exists: {target}
Error message
Destination already exists: {target} What it means
InvalidRequestError raised by _require_writable_target when the computed target file already exists and overwrite=False (the default). It is the pre-flight refusal so save_resource does not clobber existing files; no network request has been made when it fires.
Source
Thrown at paddleocr/_api_client/_resources.py:155
if not parent.is_dir():
raise InvalidRequestError(f"Destination parent must be a directory: {parent}")
return target
def _require_existing_directory(destination: str) -> Path:
dest_dir = Path(destination)
if not dest_dir.exists():
raise FileNotFoundError(destination)
if not dest_dir.is_dir():
raise InvalidRequestError(
f"Destination must be an existing directory: {destination}"
)
return dest_dir
def _require_writable_target(target: Path, overwrite: bool) -> None:
if target.exists() and not overwrite:
raise InvalidRequestError(f"Destination already exists: {target}")
def _atomic_write(target: Path, content: bytes, overwrite: bool) -> None:
fd, temp_path = tempfile.mkstemp(
prefix=f".{target.name}.tmp-",
dir=str(target.parent),
)
try:
with os.fdopen(fd, "wb") as temp_file:
temp_file.write(content)
if overwrite:
os.replace(temp_path, target)
else:
os.link(temp_path, target)
os.remove(temp_path)
except FileExistsError as e:
raise InvalidRequestError(f"Destination already exists: {target}") from e
finally:View on GitHub (pinned to 2661c7c0ef)
Solutions
- Pass overwrite=True when re-downloading is acceptable
- Skip existing files at the call site if resume semantics are wanted
- Derive unique filenames per run (job id, timestamp) to avoid collisions
Example fix
# before save_resource(url, dest) # rerun -> Destination already exists # after save_resource(url, dest, overwrite=True) # or: if not Path(dest).exists(): save_resource(url, dest)
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
if Path(target_path).exists() and not overwrite:
return target_path # resume: skip already-downloaded files Try / catch
try:
save_resource(url, dest)
except InvalidRequestError as e:
if 'already exists' not in str(e):
raise
logger.info('skipping existing %s', dest) Prevention
- Make reruns idempotent: skip existing files at the call site for resume semantics
- Pass overwrite=True deliberately when freshness matters more than safety
When it happens
Trigger: save_resource called twice with the same destination file (or same destination directory + URL basename) without overwrite=True; re-running a download script whose outputs already exist; batch helpers re-saving pages from a repeated job into the same output dir.
Common situations: Script reruns after partial completion; resumed pipelines re-downloading the same result artifacts; concurrent workers writing to one shared output dir with identical derived filenames.
Related errors
- {parent}
- {destination}
- Unsafe resource filename: ${key}
- File not found: ${path}
- resource_url is required.
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/9b927ad60a9f668e.
Report an issue: GitHub.