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
{{ message }}
Repository navigation
'DockerContainer' object has no attribute '_container' #399
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
fromtestcontainers.postgresimportPostgresContainerdefget_postgres_uri():
# Use a PostgreSQL Docker container for testingwithPostgresContainer("postgres:latest") aspostgres:
returnpostgres.get_connection_url()
im trying and failing to reproduce (on ubuntu) with:
uname -a # Linux z14-1 6.2.0-36-generic #37~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct 9 15:34:04 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
python -V # Python 3.9.18
mkdir testcontainers-python-issues-399 &&cd$_
python -m venv .venv &&. .venv/bin/activate
cat > test.py <<EOFfrom testcontainers.postgres import PostgresContainerdef get_postgres_uri(): # Use a PostgreSQL Docker container for testing with PostgresContainer("postgres:16-alpine") as postgres: return postgres.get_connection_url()print(get_postgres_uri())EOF
python test.py
and i get these logs:
$ python test.py Pulling image postgres:16-alpineContainer started: 84479badddc7Waiting to be ready...Waiting to be ready...Waiting to be ready...Waiting to be ready...Waiting to be ready...postgresql+psycopg2://test:test@localhost:32769/test
docker version is also 24:
$ docker -vDocker version 24.0.7, build afdd53b
i dont think this means there isn't an issue - maybe spending some time staring at the code of the library will show some obvious codepaths which cause the issue
In fact I'm getting more convinced this issue is present when we encounter issues with the docker client. Some refactoring and defensive coding is needed as it seems.
changed the title [-]'PostgresContainer' object has no attribute '_container'[/-][+]'DockerContainer' object has no attribute '_container'[/+]on Feb 13, 2024
Activity
alexanderankin commentedon Dec 12, 2023
im trying and failing to reproduce (on ubuntu) with:
and i get these logs:
docker version is also 24:
i dont think this means there isn't an issue - maybe spending some time staring at the code of the library will show some obvious codepaths which cause the issue
tobiaseisenschenk commentedon Dec 18, 2023
This happened for me as well on OSX. As I am using Rancher I attributed it to the unsupported runtime, but could be wrong of course.
danb27 commentedon Feb 3, 2024
Same issue!
totallyzen commentedon Feb 13, 2024
heyo, I think this isn't OS dependent, but makes for some flaky testing
I bumped into this right here on our CI.
So I think this is defo a bug related to failing to create the container
See an example run
https://github.com/testcontainers/testcontainers-python/actions/runs/7889768439/job/21530402642
totallyzen commentedon Feb 13, 2024
In fact I'm getting more convinced this issue is present when we encounter issues with the docker client. Some refactoring and defensive coding is needed as it seems.
[-]'PostgresContainer' object has no attribute '_container'[/-][+]'DockerContainer' object has no attribute '_container'[/+]fix: flaky garbage collection resulting in testing errors (#423)