MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / first_connect

Function first_connect

lib/sqlalchemy/engine/create.py:731–759  ·  view source on GitHub ↗
(
            dbapi_connection: DBAPIConnection,
            connection_record: ConnectionPoolEntry,
        )

Source from the content-addressed store, hash-verified

729 event.listen(pool, "connect", builtin_on_connect)
730
731 def first_connect(
732 dbapi_connection: DBAPIConnection,
733 connection_record: ConnectionPoolEntry,
734 ) -> None:
735 c = base.Connection(
736 engine,
737 connection=_AdhocProxiedConnection(
738 dbapi_connection, connection_record
739 ),
740 _has_events=False,
741 # reconnecting will be a reentrant condition, so if the
742 # connection goes away, Connection is then closed
743 _allow_revalidate=False,
744 # dont trigger the autobegin sequence
745 # within the up front dialect checks
746 _allow_autobegin=False,
747 )
748 c._execution_options = util.EMPTY_DICT
749
750 try:
751 dialect.initialize(c)
752 finally:
753 # note that "invalidated" and "closed" are mutually
754 # exclusive in 1.4 Connection.
755 if not c.invalidated and not c.closed:
756 # transaction is rolled back otherwise, tested by
757 # test/dialect/postgresql/test_dialect.py
758 # ::MiscBackendTest::test_initial_transaction_state
759 dialect.do_rollback(c.connection)
760
761 # previously, the "first_connect" event was used here, which was then
762 # scaled back if the "on_connect" handler were present. now,

Callers

nothing calls this directly

Calls 3

initializeMethod · 0.45
do_rollbackMethod · 0.45

Tested by

no test coverage detected