MCPcopy
hub / github.com/tortoise/tortoise-orm / _init_routers

Method _init_routers

tortoise/context.py:379–397  ·  view source on GitHub ↗

Initialize database routers for this context.

(self, routers: list[str | type] | None = None)

Source from the content-addressed store, hash-verified

377 _reset_timezone_cache()
378
379 def _init_routers(self, routers: list[str | type] | None = None) -> None:
380 """Initialize database routers for this context."""
381 from tortoise.router import router
382
383 routers = routers or []
384 router_cls = []
385 for r in routers:
386 if isinstance(r, str):
387 try:
388 module_name, class_name = r.rsplit(".", 1)
389 router_cls.append(getattr(importlib.import_module(module_name), class_name))
390 except Exception:
391 raise ConfigurationError(f"Can't import router from `{r}`")
392 elif isinstance(r, type):
393 router_cls.append(r)
394 else:
395 raise ConfigurationError("Router must be either str or type")
396 self._routers = router_cls
397 router.init_routers(router_cls)
398
399 async def generate_schemas(self, safe: bool = True) -> None:
400 """

Callers 1

initMethod · 0.95

Calls 2

ConfigurationErrorClass · 0.90
init_routersMethod · 0.80

Tested by

no test coverage detected