MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / __call__

Method __call__

lib/sqlalchemy/orm/scoping.py:196–225  ·  view source on GitHub ↗

r"""Return the current :class:`.Session`, creating it using the :attr:`.scoped_session.session_factory` if not present. :param \**kw: Keyword arguments will be passed to the :attr:`.scoped_session.session_factory` callable, if an existing :class:`.Session` is not p

(self, **kw: Any)

Source from the content-addressed store, hash-verified

194 return self.registry()
195
196 def __call__(self, **kw: Any) -> _S:
197 r"""Return the current :class:`.Session`, creating it
198 using the :attr:`.scoped_session.session_factory` if not present.
199
200 :param \**kw: Keyword arguments will be passed to the
201 :attr:`.scoped_session.session_factory` callable, if an existing
202 :class:`.Session` is not present. If the :class:`.Session` is present
203 and keyword arguments have been passed,
204 :exc:`~sqlalchemy.exc.InvalidRequestError` is raised.
205
206 """
207 if kw:
208 if self.registry.has():
209 raise sa_exc.InvalidRequestError(
210 "Scoped session is already present; "
211 "no new arguments may be specified."
212 )
213 else:
214 sess = self.session_factory(**kw)
215 self.registry.set(sess)
216 else:
217 sess = self.registry()
218 if not self._support_async and sess._is_asyncio:
219 warn_deprecated(
220 "Using `scoped_session` with asyncio is deprecated and "
221 "will raise an error in a future version. "
222 "Please use `async_scoped_session` instead.",
223 "1.4.23",
224 )
225 return sess
226
227 def configure(self, **kwargs: Any) -> None:
228 """reconfigure the :class:`.sessionmaker` used by this

Callers

nothing calls this directly

Calls 4

warn_deprecatedFunction · 0.85
registryMethod · 0.80
hasMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected