tortoise / tortoise/tortoise-orm

exception `You are running with multiple databases` with no connections

Open
#1,033 2 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
I am using the initializer function for my tests but when I try to get_connection, de default one, it actually throws me an error because Tortoise._connections is empty. That is because that function actually empties the dictionary. The thing is that get_connection use that as the source of connections but in reality is current_transaction_map dict.

tortoise.exceptions.ParamsError: You are running with multiple databases, so you should specify connection_name: []

To Reproduce
Steps to reproduce the behavior, preferaby a small code snippet.

  • call initializer func
  • call get_connection()

Expected behavior
To actually get the connection.

Additional context

This error actually popped me when trying to use in_transaction or atomic functions.

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

Trace the initializer and get_connection entry points, then compare how Tortoise._connections and current_transaction_map are populated and read. Reproduce the empty-connection case after initializer; done means get_connection() returns the default connection and in_transaction or atomic no longer raises the multiple-databases error.

Written by the indexing model from the issue text.

Assessment

Tech stack
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.