testcontainers / testcontainers/testcontainers-python

Creating a Postgres contrainer with an async driver fails

Open
#263 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #320 by @fourteekey — closed without merging
👀 requires attention 📦 package: postgres 🚀 enhancement
Dominant language
Python
Stars
2.3k
Forks
386
Avg merge
4h 40m
Merged PRs (30d)
1

Description

Hello,
When creating a new database container, testcontainers automatically tries to connect to it here, but if I specify an async driver (e.g. PostgresContainer("postgres:14.4", driver="asyncpg")) sqlalchemy tries to use that and fails because it's not in an async context.
Is there any way to skip trying to connect to the database or fix it so it can also handle async context?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at testcontainers/core/generic.py around line 55 and trace how PostgresContainer("postgres:14.4", driver="asyncpg") builds and connects through SQLAlchemy. Check the existing handling of driver selection and the closed linked pull request for context. Done means creating a container with an async driver no longer fails during automatic connection, with the intended skip or async-context behavior covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python, sqlalchemy
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.