Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec_run with demux=True: output is None instead of empty bytes #3172

Open
just-max opened this issue Sep 2, 2023 · 1 comment · May be fixed by #3201
Open

exec_run with demux=True: output is None instead of empty bytes #3172

just-max opened this issue Sep 2, 2023 · 1 comment · May be fixed by #3201

Comments

@just-max
Copy link

just-max commented Sep 2, 2023

When calling exec_run with demux=True, the documentation states that a pair of bytes is returned.

However, if no standard output (or no standard error) is produced, then the corresponding tuple entry is None instead of an empty bytes (b'').

Minimum working example:

import docker
client = docker.from_env()
container = client.containers.run("alpine:latest", detach=True, tty=True)
container.exec_run(("sh", "-c", "echo out >&1"), demux=True)  # ExecResult(exit_code=0, output=(b'out\n', None))
container.exec_run(("sh", "-c", "echo err >&2"), demux=True)  # ExecResult(exit_code=0, output=(None, b'err\n'))

The expected behaviour is that both tuple entries are always bytes. Alternatively, the possibility of returning None should be documented clearly!

@Khushiyant
Copy link
Contributor

Yes, I checked that in documentation here and it seems very easily solvable as below:

+ exec_output = tuple(b'' if x is None else x for x in exec_output)

Khushiyant added a commit to Khushiyant/docker-py that referenced this issue Dec 17, 2023
@Khushiyant Khushiyant linked a pull request Dec 17, 2023 that will close this issue
Khushiyant added a commit to Khushiyant/docker-py that referenced this issue Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants