testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

fix: get_wrapped_container returns container all the time now

Open alexanderankin opened this issue 2 months ago • 2 comments

fix #905

alexanderankin avatar Oct 15 '25 14:10 alexanderankin

ok, have to think about this one more carefully. seems like there is more to this than appears

alexanderankin avatar Oct 15 '25 14:10 alexanderankin

it throws docker api exception or something. its in the docstr of the get method. just navigate to it and you should see it also

On Thu, Oct 16, 2025 at 8:58 AM Ivan @.***> wrote:

@.**** approved this pull request.

In core/testcontainers/compose/compose.py https://github.com/testcontainers/testcontainers-python/pull/906#discussion_r2435813404 :

@@ -259,6 +263,13 @@ def compose_command_property(self) -> list[str]: docker_compose_cmd += ["--env-file", env_file] return docker_compose_cmd

  • def _get_docker_client(self) -> DockerClient:

⬇️ Suggested change

  • def _get_docker_client(self) -> DockerClient:
  • def _get_docker_client(self) -> DockerClient:
  •    if self._docker_client is None:
    
  •        self._docker_client = DockerClient(**(self.docker_client_kw or {}))
    
  •    return self._docker_client
    

In core/testcontainers/compose/compose.py https://github.com/testcontainers/testcontainers-python/pull/906#discussion_r2435816288 :

     """Get the underlying container object for compatibility."""
  •    return self
    
  •    return self._docker_compose._get_docker_client().containers.get(self.ID)
    

Dumb question: can .containers.get(self.ID) return a value other than Container, e.g. None?

what if the container is not found?

— Reply to this email directly, view it on GitHub https://github.com/testcontainers/testcontainers-python/pull/906#pullrequestreview-3344710048, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACECGJDPPFF3B2BECIZBBUD3X6I6RAVCNFSM6AAAAACJIPB3Z2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTGNBUG4YTAMBUHA . You are receiving this because you authored the thread.Message ID: @.*** com>

alexanderankin avatar Oct 16 '25 14:10 alexanderankin