tortoise / tortoise/tortoise-orm
tortoise.contrib.test.initializer relies on PGDATABASE env var even if db_url is provided
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
When supplying a db_url argument to tortoise.contrib.test.initializer which includes the database name
(postgres://user:pass@$host:port/db), it does not respect the DB and instead uses the username supplied as DB name
To Reproduce
Reproducing with:
pytest 8.4.1
tortoise 0.25.1
asyncpg 0.30.0
pytest-asyncio 1.0.0
# conftest.py
@pytest.fixture(scope="session", autouse=True)
def initialize_tests(request):
db_url = os.environ.get("TEST_DATABASE_URL")
os.environ["PGDATABASE"] = "dbname" # <-- removing this should raise:
# tortoise.exceptions.DBConnectionError: Can't establish connection to default database. Verify environment PGDATABASE
initializer(["foo.bar"], db_url=db_url)
request.addfinalizer(finalizer)
Expected behavior
The DB name in the URL should be respected
Additional context
nil
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at tortoise.contrib.test.initializer and reproduce the issue using the conftest.py fixture and pytest setup shown. Verify that a db_url containing a database name works without PGDATABASE, and run the relevant pytest coverage to confirm the expected connection behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100