Skip to content

Fix BlackSheep cross-task database access#2248

Open
Sanjays2402 wants to merge 1 commit into
tortoise:developfrom
Sanjays2402:fix/blacksheep-global-context
Open

Fix BlackSheep cross-task database access#2248
Sanjays2402 wants to merge 1 commit into
tortoise:developfrom
Sanjays2402:fix/blacksheep-global-context

Conversation

@Sanjays2402

Copy link
Copy Markdown

Description

Enable the global context fallback when the BlackSheep integration initializes Tortoise.

Motivation and Context

BlackSheep startup and request handlers run in separate asyncio tasks. Without the fallback, every request-side database query raises No TortoiseContext is currently active. Fixes #2244.

How Has This Been Tested?

The regression test fails without the flag and passes with it. A BlackSheep lifecycle probe also initialized the ORM in one task and successfully queried SQLite from another.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation. (Not required.)
  • I have updated the documentation accordingly. (Not required.)
  • I have added the changelog accordingly. (Not required.)
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed. (The focused test passed; the full suite was not run.)

BlackSheep initializes the ORM in its lifespan task, but request tasks could not see that context because the global fallback was disabled. Enable the same fallback used by the other ASGI integrations and add a regression test for the startup configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant