mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2025-12-27 02:56:36 +00:00
fix(restore): handle bytes stdin correctly in subprocess wrapper
Avoid passing raw bytes/str via stdin to subprocess.run(), which caused "'bytes' object has no attribute 'fileno'" and "stdin and input arguments may not both be used" errors. If stdin is bytes or str, pass it via input= instead; otherwise forward stdin unchanged. This fixes Postgres restore failures in E2E tests without changing productive restore logic. https://chatgpt.com/share/694ed70d-9e04-800f-8dec-edf08e6e2082
This commit is contained in:
@@ -13,13 +13,21 @@ def run(
|
|||||||
env: Optional[dict] = None,
|
env: Optional[dict] = None,
|
||||||
) -> subprocess.CompletedProcess:
|
) -> subprocess.CompletedProcess:
|
||||||
try:
|
try:
|
||||||
return subprocess.run(
|
kwargs: dict = {
|
||||||
cmd,
|
"check": True,
|
||||||
check=True,
|
"capture_output": capture,
|
||||||
stdin=stdin,
|
"env": env,
|
||||||
capture_output=capture,
|
}
|
||||||
env=env,
|
|
||||||
)
|
# If stdin is raw data (bytes/str), pass it via input=.
|
||||||
|
# IMPORTANT: when using input=..., do NOT pass stdin=... as well.
|
||||||
|
if isinstance(stdin, (bytes, str)):
|
||||||
|
kwargs["input"] = stdin
|
||||||
|
else:
|
||||||
|
kwargs["stdin"] = stdin
|
||||||
|
|
||||||
|
return subprocess.run(cmd, **kwargs)
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
msg = f"ERROR: command failed ({e.returncode}): {' '.join(cmd)}"
|
msg = f"ERROR: command failed ({e.returncode}): {' '.join(cmd)}"
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user