Thanks to visit codestin.com
Credit goes to github.com

Skip to content

'DockerContainer' object has no attribute '_container' #399

@theopfr

Description

@theopfr

Creating Postgres Container instance results in error: 'PostgresContainer' object has no attribute '_container'

I tried starting a Postgres container and got the following error:

Exception ignored in: <function DockerContainer.__del__ at 0x7f1da5122b80>
Traceback (most recent call last):
  File "/.venv/lib/python3.9/site-packages/testcontainers/core/container.py", line 80, in __del__
AttributeError: 'PostgresContainer' object has no attribute '_container'

I already saw an issue #353 which was about the same error but it seems to persist.
See the code I used below.

To Reproduce

from testcontainers.postgres import PostgresContainer

def get_postgres_uri():
    # Use a PostgreSQL Docker container for testing
    with PostgresContainer("postgres:latest") as postgres:
        return postgres.get_connection_url()

I also tried out the code in the postgres/tests/test_postgres.py file and it failed with the same error message.

Runtime environment

OS: Pop!_OS 22.04 LTS x86_64
Python version: Python 3.9.12
Docker version: 24.0.5
testcontainers version: 3.7.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions