Skip to content

Commit 529edcc

Browse files
authored
Skips database selection if the router is not configured. (#1915)
1 parent a399d1a commit 529edcc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.rst

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Changelog
99
0.24
1010
====
1111

12+
0.24.3 (unreleased)
13+
------
14+
Changed
15+
^^^^^^^
16+
- Skip database selection if the router is not configured to improve performance (#1915)
17+
1218
0.24.2
1319
------
1420

tortoise/router.py

+6
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ def _db_route(self, model: type[Model], action: str) -> BaseDBAsyncClient | None
3636
return None
3737

3838
def db_for_read(self, model: type[Model]) -> BaseDBAsyncClient | None:
39+
if not self._routers:
40+
return None
41+
3942
return self._db_route(model, "db_for_read")
4043

4144
def db_for_write(self, model: type[Model]) -> BaseDBAsyncClient | None:
45+
if not self._routers:
46+
return None
47+
4248
return self._db_route(model, "db_for_write")
4349

4450

0 commit comments

Comments
 (0)