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

Method __post_init__

tortoise/config.py:110–144  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

108 timezone: str | None = None
109
110 def __post_init__(self) -> None:
111 if not isinstance(self.connections, dict) or not self.connections:
112 raise ConfigurationError("TortoiseConfig.connections must be a non-empty dict")
113 for name, conn in self.connections.items():
114 if not isinstance(name, str) or not name:
115 raise ConfigurationError("Connection names must be non-empty strings")
116 if not isinstance(conn, (ConnectionConfig, DBUrlConfig)):
117 raise ConfigurationError(
118 "Connection values must be ConnectionConfig or DBUrlConfig"
119 )
120
121 if not isinstance(self.apps, dict) or not self.apps:
122 raise ConfigurationError("TortoiseConfig.apps must be a non-empty dict")
123 for name, app in self.apps.items():
124 if not isinstance(name, str) or not name:
125 raise ConfigurationError("App names must be non-empty strings")
126 if not isinstance(app, AppConfig):
127 raise ConfigurationError("App values must be AppConfig")
128 if app.default_connection and app.default_connection not in self.connections:
129 raise ConfigurationError(
130 f'App "{name}" refers to unknown connection "{app.default_connection}"'
131 )
132
133 if self.routers is not None:
134 if not isinstance(self.routers, list):
135 raise ConfigurationError("TortoiseConfig.routers must be a list or None")
136 for router in self.routers:
137 if not isinstance(router, (str, type)):
138 raise ConfigurationError("Routers must be str or type")
139
140 if self.use_tz is not None and not isinstance(self.use_tz, bool):
141 raise ConfigurationError("TortoiseConfig.use_tz must be a bool or None")
142
143 if self.timezone is not None and not isinstance(self.timezone, str):
144 raise ConfigurationError("TortoiseConfig.timezone must be a string or None")
145
146 def to_dict(self) -> dict[str, Any]:
147 connections = {name: conn.to_config() for name, conn in self.connections.items()}

Callers

nothing calls this directly

Calls 2

ConfigurationErrorClass · 0.90
itemsMethod · 0.80

Tested by

no test coverage detected