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:
2025-12-26 19:42:17 +01:00
parent cf6f4d8326
commit 7b55d59300

View File

@@ -13,13 +13,21 @@ def run(
env: Optional[dict] = None,
) -> subprocess.CompletedProcess:
try:
return subprocess.run(
cmd,
check=True,
stdin=stdin,
capture_output=capture,
env=env,
)
kwargs: dict = {
"check": True,
"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:
msg = f"ERROR: command failed ({e.returncode}): {' '.join(cmd)}"
print(msg, file=sys.stderr)