r"""Return a :class:`_engine.Connection` object corresponding to this :class:`.Session` object's transactional state. Either the :class:`_engine.Connection` corresponding to the current transaction is returned, or if no transaction is in progress, a new one is begun
(
self,
bind_arguments: Optional[_BindArguments] = None,
execution_options: Optional[CoreExecuteOptionsParameter] = None,
)
| 2093 | trans.prepare() |
| 2094 | |
| 2095 | def connection( |
| 2096 | self, |
| 2097 | bind_arguments: Optional[_BindArguments] = None, |
| 2098 | execution_options: Optional[CoreExecuteOptionsParameter] = None, |
| 2099 | ) -> Connection: |
| 2100 | r"""Return a :class:`_engine.Connection` object corresponding to this |
| 2101 | :class:`.Session` object's transactional state. |
| 2102 | |
| 2103 | Either the :class:`_engine.Connection` corresponding to the current |
| 2104 | transaction is returned, or if no transaction is in progress, a new |
| 2105 | one is begun and the :class:`_engine.Connection` |
| 2106 | returned (note that no |
| 2107 | transactional state is established with the DBAPI until the first |
| 2108 | SQL statement is emitted). |
| 2109 | |
| 2110 | Ambiguity in multi-bind or unbound :class:`.Session` objects can be |
| 2111 | resolved through any of the optional keyword arguments. This |
| 2112 | ultimately makes usage of the :meth:`.get_bind` method for resolution. |
| 2113 | |
| 2114 | :param bind_arguments: dictionary of bind arguments. May include |
| 2115 | "mapper", "bind", "clause", other custom arguments that are passed |
| 2116 | to :meth:`.Session.get_bind`. |
| 2117 | |
| 2118 | :param execution_options: a dictionary of execution options that will |
| 2119 | be passed to :meth:`_engine.Connection.execution_options`, **when the |
| 2120 | connection is first procured only**. If the connection is already |
| 2121 | present within the :class:`.Session`, a warning is emitted and |
| 2122 | the arguments are ignored. |
| 2123 | |
| 2124 | .. seealso:: |
| 2125 | |
| 2126 | :ref:`session_transaction_isolation` |
| 2127 | |
| 2128 | """ |
| 2129 | |
| 2130 | if bind_arguments: |
| 2131 | bind = bind_arguments.pop("bind", None) |
| 2132 | |
| 2133 | if bind is None: |
| 2134 | bind = self.get_bind(**bind_arguments) |
| 2135 | else: |
| 2136 | bind = self.get_bind() |
| 2137 | |
| 2138 | return self._connection_for_bind( |
| 2139 | bind, |
| 2140 | execution_options=execution_options, |
| 2141 | ) |
| 2142 | |
| 2143 | def _connection_for_bind( |
| 2144 | self, |