MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / __call__

Method __call__

lib/sqlalchemy/ext/asyncio/scoping.py:165–195  ·  view source on GitHub ↗

r"""Return the current :class:`.AsyncSession`, 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:`.AsyncSession

(self, **kw: Any)

Source from the content-addressed store, hash-verified

163 return self.registry()
164
165 def __call__(self, **kw: Any) -> _AS:
166 r"""Return the current :class:`.AsyncSession`, creating it
167 using the :attr:`.scoped_session.session_factory` if not present.
168
169 :param \**kw: Keyword arguments will be passed to the
170 :attr:`.scoped_session.session_factory` callable, if an existing
171 :class:`.AsyncSession` is not present. If the
172 :class:`.AsyncSession` is present
173 and keyword arguments have been passed,
174 :exc:`~sqlalchemy.exc.InvalidRequestError` is raised.
175
176 """
177 if kw:
178 if self.registry.has():
179 raise sa_exc.InvalidRequestError(
180 "Scoped session is already present; "
181 "no new arguments may be specified."
182 )
183 else:
184 sess = self.session_factory(**kw)
185 self.registry.set(sess)
186 else:
187 sess = self.registry()
188 if not self._support_async and sess._is_asyncio:
189 warn_deprecated(
190 "Using `scoped_session` with asyncio is deprecated and "
191 "will raise an error in a future version. "
192 "Please use `async_scoped_session` instead.",
193 "1.4.23",
194 )
195 return sess
196
197 def configure(self, **kwargs: Any) -> None:
198 """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