tortoise / tortoise/tortoise-orm

Cannot drop postgres test db

Open
#1,437 0 comments 0 reactions 0 assignees View on GitHub

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
finalizer() fails with

E   asyncpg.exceptions.ObjectInUseError: database "test_db" is being accessed by other users

E   DETAIL:  There is 1 other session using the database.

To Reproduce

@pytest.fixture(scope="session")
def event_loop():
    policy = asyncio.get_event_loop_policy()
    loop = policy.new_event_loop()
    yield loop
    loop.close()


@pytest.fixture(scope="session", autouse=True)
def initialize_tests(request, event_loop):
    initializer(models, db_url=test_db_url)
    request.addfinalizer(finalizer)

Expected behavior
I expect the test db to be dropped as finalizer is calling connections.close_all() before trying to delete the db

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 by tracing the finalizer and connections.close_all() referenced in the report, then reproduce the session-scoped pytest fixture with the PostgreSQL test database. Done means the finalizer can drop test_db without asyncpg.exceptions.ObjectInUseError or another session remaining.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.