You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to wait_for_logs on a docker compose container is failing. Cause seems to be .decode() being used twice (i.e. attempt to .decode() a string already decoded earlier).
wait_for_logs is .decode()-ing here the result of DockerCompose.get_logs()
DockerCompose.get_logs()here has already decoded the stdout byte stream.
Attempt to decode a string object fails.
To Reproduce
fromtestcontainers.composeimportDockerComposefromtestcontainers.core.waiting_utilsimportwait_for_logscompose=DockerCompose("./docker/", compose_file_name="docker-compose.yml", services=['slim-db'])
compose.start()
delay=wait_for_logs(compose, "database system is ready to accept connections")
produces an AttributeError:
AttributeError Traceback (most recent call last)
----> [1] delay = wait_for_logs(compose, "database system is ready to accept connections")
File ~/myproject/.venv/lib/python3.12/site-packages/testcontainers/core/waiting_utils.py:102, in wait_for_logs(container, predicate, timeout, interval)
100 while True:
101 duration = time.time() - start
--> 102 stdout = container.get_logs()[0].decode()
103 stderr = container.get_logs()[1].decode()
104 if predicate(stdout) or predicate(stderr):
AttributeError: 'str' object has no attribute 'decode'
Runtime environment
This error arises in python versions 3.10, 3.11, and 3.12. The current environment:
Other Notes
As a simple test, a quick patch (I removed the .decode() in the get_logs method of DockerCompose) resolves this issue for me. I have not tested (and don't really have the capacity to do so, unfortunately) the impact of this change across other parts of the code base. There may be other places which expect a string instead of a byte stream -- I don't yet know.
The text was updated successfully, but these errors were encountered:
Describe the bug
Attempting to
wait_for_logs
on a docker compose container is failing. Cause seems to be.decode()
being used twice (i.e. attempt to.decode()
a string already decoded earlier).wait_for_logs
is.decode()
-ing here the result ofDockerCompose.get_logs()
DockerCompose.get_logs()
here has already decoded the stdout byte stream.To Reproduce
produces an
AttributeError
:Runtime environment
This error arises in python versions 3.10, 3.11, and 3.12. The current environment:
Other Notes
As a simple test, a quick patch (I removed the
.decode()
in theget_logs
method of DockerCompose) resolves this issue for me. I have not tested (and don't really have the capacity to do so, unfortunately) the impact of this change across other parts of the code base. There may be other places which expect a string instead of a byte stream -- I don't yet know.The text was updated successfully, but these errors were encountered: