From 7b55d5930076cd95694da6b88dfe0144e5258e15 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 26 Dec 2025 19:42:17 +0100 Subject: [PATCH] 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 --- src/baudolo/restore/run.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/baudolo/restore/run.py b/src/baudolo/restore/run.py index 05fea8c..a7f13b4 100644 --- a/src/baudolo/restore/run.py +++ b/src/baudolo/restore/run.py @@ -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)