tortoise / tortoise/tortoise-orm

Transaction execution context affects query building

Open
#1,380 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

This works just fine:

async with in_transaction(connection_name='tournament') as conn:
        await conn.execute_query(f"SET search_path TO tournament_schema")              
        q = Tournament.get(id=id)
        item = await q

The following gives an 'Object does not exist' error:

q = Tournament.get(id=id)
async with in_transaction(connection_name='tournament') as conn:
        await conn.execute_query(f"SET search_path TO tournament_schema")              
        item = await q

I wouldn't expect the transaction execution context to affect the building of the query.

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 reproducing the two async examples using Tournament.get, in_transaction, and the PostgreSQL search_path change. Trace where the query is built versus where the transaction connection is selected. Done means constructing the query before entering the transaction behaves consistently with constructing it inside the transaction, without an Object does not exist error.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.