MCPcopy
hub / github.com/django/django / connect

Method connect

django/db/backends/base/base.py:237–261  ·  view source on GitHub ↗

Connect to the database. Assume that the connection is closed.

(self)

Source from the content-addressed store, hash-verified

235
236 @async_unsafe
237 def connect(self):
238 """Connect to the database. Assume that the connection is closed."""
239 # Check for invalid configurations.
240 self.check_settings()
241 # In case the previous connection was closed while in an atomic block
242 self.in_atomic_block = False
243 self.savepoint_ids = []
244 self.atomic_blocks = []
245 self.needs_rollback = False
246 # Reset parameters defining when to close/health-check the connection.
247 self.health_check_enabled = self.settings_dict["CONN_HEALTH_CHECKS"]
248 max_age = self.settings_dict["CONN_MAX_AGE"]
249 self.close_at = None if max_age is None else time.monotonic() + max_age
250 self.closed_in_transaction = False
251 self.errors_occurred = False
252 # New connections are healthy.
253 self.health_check_done = True
254 # Establish the connection
255 conn_params = self.get_connection_params()
256 self.connection = self.get_new_connection(conn_params)
257 self.set_autocommit(self.settings_dict["AUTOCOMMIT"])
258 self.init_connection_state()
259 connection_created.send(sender=self.__class__, connection=self)
260
261 self.run_on_commit = []
262
263 def check_settings(self):
264 if self.settings_dict["TIME_ZONE"] is not None and not settings.USE_TZ:

Callers 7

ensure_connectionMethod · 0.95
get_new_connectionMethod · 0.45
get_new_connectionMethod · 0.45
get_new_connectionMethod · 0.45
_clone_test_dbMethod · 0.45
get_new_connectionMethod · 0.45

Calls 6

check_settingsMethod · 0.95
get_connection_paramsMethod · 0.95
get_new_connectionMethod · 0.95
set_autocommitMethod · 0.95
init_connection_stateMethod · 0.95
sendMethod · 0.45

Tested by

no test coverage detected