SQLAlchemy 2.1.0b1__cp313-cp313-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. sqlalchemy/__init__.py +295 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +161 -0
  4. sqlalchemy/connectors/asyncio.py +476 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/dialects/__init__.py +62 -0
  7. sqlalchemy/dialects/_typing.py +30 -0
  8. sqlalchemy/dialects/mssql/__init__.py +88 -0
  9. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  10. sqlalchemy/dialects/mssql/base.py +4110 -0
  11. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  12. sqlalchemy/dialects/mssql/json.py +129 -0
  13. sqlalchemy/dialects/mssql/provision.py +185 -0
  14. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  15. sqlalchemy/dialects/mssql/pyodbc.py +758 -0
  16. sqlalchemy/dialects/mysql/__init__.py +106 -0
  17. sqlalchemy/dialects/mysql/_mariadb_shim.py +312 -0
  18. sqlalchemy/dialects/mysql/aiomysql.py +226 -0
  19. sqlalchemy/dialects/mysql/asyncmy.py +214 -0
  20. sqlalchemy/dialects/mysql/base.py +3870 -0
  21. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  22. sqlalchemy/dialects/mysql/dml.py +279 -0
  23. sqlalchemy/dialects/mysql/enumerated.py +277 -0
  24. sqlalchemy/dialects/mysql/expression.py +146 -0
  25. sqlalchemy/dialects/mysql/json.py +91 -0
  26. sqlalchemy/dialects/mysql/mariadb.py +67 -0
  27. sqlalchemy/dialects/mysql/mariadbconnector.py +330 -0
  28. sqlalchemy/dialects/mysql/mysqlconnector.py +296 -0
  29. sqlalchemy/dialects/mysql/mysqldb.py +312 -0
  30. sqlalchemy/dialects/mysql/provision.py +147 -0
  31. sqlalchemy/dialects/mysql/pymysql.py +157 -0
  32. sqlalchemy/dialects/mysql/pyodbc.py +156 -0
  33. sqlalchemy/dialects/mysql/reflection.py +724 -0
  34. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  35. sqlalchemy/dialects/mysql/types.py +845 -0
  36. sqlalchemy/dialects/oracle/__init__.py +83 -0
  37. sqlalchemy/dialects/oracle/base.py +3871 -0
  38. sqlalchemy/dialects/oracle/cx_oracle.py +1522 -0
  39. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  40. sqlalchemy/dialects/oracle/oracledb.py +894 -0
  41. sqlalchemy/dialects/oracle/provision.py +288 -0
  42. sqlalchemy/dialects/oracle/types.py +350 -0
  43. sqlalchemy/dialects/oracle/vector.py +368 -0
  44. sqlalchemy/dialects/postgresql/__init__.py +171 -0
  45. sqlalchemy/dialects/postgresql/_psycopg_common.py +193 -0
  46. sqlalchemy/dialects/postgresql/array.py +534 -0
  47. sqlalchemy/dialects/postgresql/asyncpg.py +1331 -0
  48. sqlalchemy/dialects/postgresql/base.py +5729 -0
  49. sqlalchemy/dialects/postgresql/bitstring.py +327 -0
  50. sqlalchemy/dialects/postgresql/dml.py +360 -0
  51. sqlalchemy/dialects/postgresql/ext.py +593 -0
  52. sqlalchemy/dialects/postgresql/hstore.py +413 -0
  53. sqlalchemy/dialects/postgresql/json.py +407 -0
  54. sqlalchemy/dialects/postgresql/named_types.py +521 -0
  55. sqlalchemy/dialects/postgresql/operators.py +130 -0
  56. sqlalchemy/dialects/postgresql/pg8000.py +672 -0
  57. sqlalchemy/dialects/postgresql/pg_catalog.py +344 -0
  58. sqlalchemy/dialects/postgresql/provision.py +175 -0
  59. sqlalchemy/dialects/postgresql/psycopg.py +815 -0
  60. sqlalchemy/dialects/postgresql/psycopg2.py +887 -0
  61. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  62. sqlalchemy/dialects/postgresql/ranges.py +1002 -0
  63. sqlalchemy/dialects/postgresql/types.py +388 -0
  64. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  65. sqlalchemy/dialects/sqlite/aiosqlite.py +321 -0
  66. sqlalchemy/dialects/sqlite/base.py +3050 -0
  67. sqlalchemy/dialects/sqlite/dml.py +279 -0
  68. sqlalchemy/dialects/sqlite/json.py +89 -0
  69. sqlalchemy/dialects/sqlite/provision.py +223 -0
  70. sqlalchemy/dialects/sqlite/pysqlcipher.py +157 -0
  71. sqlalchemy/dialects/sqlite/pysqlite.py +754 -0
  72. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  73. sqlalchemy/engine/__init__.py +62 -0
  74. sqlalchemy/engine/_processors_cy.cp313-win_arm64.pyd +0 -0
  75. sqlalchemy/engine/_processors_cy.py +92 -0
  76. sqlalchemy/engine/_result_cy.cp313-win_arm64.pyd +0 -0
  77. sqlalchemy/engine/_result_cy.py +633 -0
  78. sqlalchemy/engine/_row_cy.cp313-win_arm64.pyd +0 -0
  79. sqlalchemy/engine/_row_cy.py +232 -0
  80. sqlalchemy/engine/_util_cy.cp313-win_arm64.pyd +0 -0
  81. sqlalchemy/engine/_util_cy.py +136 -0
  82. sqlalchemy/engine/base.py +3334 -0
  83. sqlalchemy/engine/characteristics.py +155 -0
  84. sqlalchemy/engine/create.py +869 -0
  85. sqlalchemy/engine/cursor.py +2416 -0
  86. sqlalchemy/engine/default.py +2393 -0
  87. sqlalchemy/engine/events.py +965 -0
  88. sqlalchemy/engine/interfaces.py +3465 -0
  89. sqlalchemy/engine/mock.py +134 -0
  90. sqlalchemy/engine/processors.py +82 -0
  91. sqlalchemy/engine/reflection.py +2100 -0
  92. sqlalchemy/engine/result.py +1932 -0
  93. sqlalchemy/engine/row.py +397 -0
  94. sqlalchemy/engine/strategies.py +16 -0
  95. sqlalchemy/engine/url.py +922 -0
  96. sqlalchemy/engine/util.py +156 -0
  97. sqlalchemy/event/__init__.py +26 -0
  98. sqlalchemy/event/api.py +220 -0
  99. sqlalchemy/event/attr.py +674 -0
  100. sqlalchemy/event/base.py +472 -0
  101. sqlalchemy/event/legacy.py +258 -0
  102. sqlalchemy/event/registry.py +390 -0
  103. sqlalchemy/events.py +17 -0
  104. sqlalchemy/exc.py +922 -0
  105. sqlalchemy/ext/__init__.py +11 -0
  106. sqlalchemy/ext/associationproxy.py +2072 -0
  107. sqlalchemy/ext/asyncio/__init__.py +29 -0
  108. sqlalchemy/ext/asyncio/base.py +281 -0
  109. sqlalchemy/ext/asyncio/engine.py +1475 -0
  110. sqlalchemy/ext/asyncio/exc.py +21 -0
  111. sqlalchemy/ext/asyncio/result.py +994 -0
  112. sqlalchemy/ext/asyncio/scoping.py +1667 -0
  113. sqlalchemy/ext/asyncio/session.py +1993 -0
  114. sqlalchemy/ext/automap.py +1701 -0
  115. sqlalchemy/ext/baked.py +559 -0
  116. sqlalchemy/ext/compiler.py +600 -0
  117. sqlalchemy/ext/declarative/__init__.py +65 -0
  118. sqlalchemy/ext/declarative/extensions.py +560 -0
  119. sqlalchemy/ext/horizontal_shard.py +481 -0
  120. sqlalchemy/ext/hybrid.py +1877 -0
  121. sqlalchemy/ext/indexable.py +364 -0
  122. sqlalchemy/ext/instrumentation.py +450 -0
  123. sqlalchemy/ext/mutable.py +1081 -0
  124. sqlalchemy/ext/orderinglist.py +439 -0
  125. sqlalchemy/ext/serializer.py +185 -0
  126. sqlalchemy/future/__init__.py +16 -0
  127. sqlalchemy/future/engine.py +15 -0
  128. sqlalchemy/inspection.py +174 -0
  129. sqlalchemy/log.py +283 -0
  130. sqlalchemy/orm/__init__.py +175 -0
  131. sqlalchemy/orm/_orm_constructors.py +2694 -0
  132. sqlalchemy/orm/_typing.py +179 -0
  133. sqlalchemy/orm/attributes.py +2868 -0
  134. sqlalchemy/orm/base.py +970 -0
  135. sqlalchemy/orm/bulk_persistence.py +2152 -0
  136. sqlalchemy/orm/clsregistry.py +582 -0
  137. sqlalchemy/orm/collections.py +1568 -0
  138. sqlalchemy/orm/context.py +3471 -0
  139. sqlalchemy/orm/decl_api.py +2257 -0
  140. sqlalchemy/orm/decl_base.py +2304 -0
  141. sqlalchemy/orm/dependency.py +1306 -0
  142. sqlalchemy/orm/descriptor_props.py +1183 -0
  143. sqlalchemy/orm/dynamic.py +300 -0
  144. sqlalchemy/orm/evaluator.py +379 -0
  145. sqlalchemy/orm/events.py +3386 -0
  146. sqlalchemy/orm/exc.py +237 -0
  147. sqlalchemy/orm/identity.py +302 -0
  148. sqlalchemy/orm/instrumentation.py +746 -0
  149. sqlalchemy/orm/interfaces.py +1589 -0
  150. sqlalchemy/orm/loading.py +1684 -0
  151. sqlalchemy/orm/mapped_collection.py +557 -0
  152. sqlalchemy/orm/mapper.py +4406 -0
  153. sqlalchemy/orm/path_registry.py +814 -0
  154. sqlalchemy/orm/persistence.py +1789 -0
  155. sqlalchemy/orm/properties.py +973 -0
  156. sqlalchemy/orm/query.py +3521 -0
  157. sqlalchemy/orm/relationships.py +3570 -0
  158. sqlalchemy/orm/scoping.py +2220 -0
  159. sqlalchemy/orm/session.py +5389 -0
  160. sqlalchemy/orm/state.py +1175 -0
  161. sqlalchemy/orm/state_changes.py +196 -0
  162. sqlalchemy/orm/strategies.py +3480 -0
  163. sqlalchemy/orm/strategy_options.py +2544 -0
  164. sqlalchemy/orm/sync.py +164 -0
  165. sqlalchemy/orm/unitofwork.py +798 -0
  166. sqlalchemy/orm/util.py +2435 -0
  167. sqlalchemy/orm/writeonly.py +694 -0
  168. sqlalchemy/pool/__init__.py +41 -0
  169. sqlalchemy/pool/base.py +1514 -0
  170. sqlalchemy/pool/events.py +372 -0
  171. sqlalchemy/pool/impl.py +582 -0
  172. sqlalchemy/py.typed +0 -0
  173. sqlalchemy/schema.py +72 -0
  174. sqlalchemy/sql/__init__.py +153 -0
  175. sqlalchemy/sql/_dml_constructors.py +132 -0
  176. sqlalchemy/sql/_elements_constructors.py +2147 -0
  177. sqlalchemy/sql/_orm_types.py +20 -0
  178. sqlalchemy/sql/_selectable_constructors.py +773 -0
  179. sqlalchemy/sql/_typing.py +486 -0
  180. sqlalchemy/sql/_util_cy.cp313-win_arm64.pyd +0 -0
  181. sqlalchemy/sql/_util_cy.py +127 -0
  182. sqlalchemy/sql/annotation.py +590 -0
  183. sqlalchemy/sql/base.py +2602 -0
  184. sqlalchemy/sql/cache_key.py +1066 -0
  185. sqlalchemy/sql/coercions.py +1373 -0
  186. sqlalchemy/sql/compiler.py +8259 -0
  187. sqlalchemy/sql/crud.py +1807 -0
  188. sqlalchemy/sql/ddl.py +1928 -0
  189. sqlalchemy/sql/default_comparator.py +654 -0
  190. sqlalchemy/sql/dml.py +1974 -0
  191. sqlalchemy/sql/elements.py +6016 -0
  192. sqlalchemy/sql/events.py +458 -0
  193. sqlalchemy/sql/expression.py +170 -0
  194. sqlalchemy/sql/functions.py +2257 -0
  195. sqlalchemy/sql/lambdas.py +1443 -0
  196. sqlalchemy/sql/naming.py +209 -0
  197. sqlalchemy/sql/operators.py +2897 -0
  198. sqlalchemy/sql/roles.py +332 -0
  199. sqlalchemy/sql/schema.py +6560 -0
  200. sqlalchemy/sql/selectable.py +7497 -0
  201. sqlalchemy/sql/sqltypes.py +4050 -0
  202. sqlalchemy/sql/traversals.py +1042 -0
  203. sqlalchemy/sql/type_api.py +2425 -0
  204. sqlalchemy/sql/util.py +1495 -0
  205. sqlalchemy/sql/visitors.py +1157 -0
  206. sqlalchemy/testing/__init__.py +96 -0
  207. sqlalchemy/testing/assertions.py +1007 -0
  208. sqlalchemy/testing/assertsql.py +519 -0
  209. sqlalchemy/testing/asyncio.py +128 -0
  210. sqlalchemy/testing/config.py +440 -0
  211. sqlalchemy/testing/engines.py +478 -0
  212. sqlalchemy/testing/entities.py +117 -0
  213. sqlalchemy/testing/exclusions.py +476 -0
  214. sqlalchemy/testing/fixtures/__init__.py +30 -0
  215. sqlalchemy/testing/fixtures/base.py +366 -0
  216. sqlalchemy/testing/fixtures/mypy.py +247 -0
  217. sqlalchemy/testing/fixtures/orm.py +227 -0
  218. sqlalchemy/testing/fixtures/sql.py +538 -0
  219. sqlalchemy/testing/pickleable.py +155 -0
  220. sqlalchemy/testing/plugin/__init__.py +6 -0
  221. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  222. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  223. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  224. sqlalchemy/testing/profiling.py +329 -0
  225. sqlalchemy/testing/provision.py +596 -0
  226. sqlalchemy/testing/requirements.py +1973 -0
  227. sqlalchemy/testing/schema.py +198 -0
  228. sqlalchemy/testing/suite/__init__.py +19 -0
  229. sqlalchemy/testing/suite/test_cte.py +237 -0
  230. sqlalchemy/testing/suite/test_ddl.py +420 -0
  231. sqlalchemy/testing/suite/test_dialect.py +776 -0
  232. sqlalchemy/testing/suite/test_insert.py +630 -0
  233. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  234. sqlalchemy/testing/suite/test_results.py +660 -0
  235. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  236. sqlalchemy/testing/suite/test_select.py +2112 -0
  237. sqlalchemy/testing/suite/test_sequence.py +317 -0
  238. sqlalchemy/testing/suite/test_table_via_select.py +686 -0
  239. sqlalchemy/testing/suite/test_types.py +2253 -0
  240. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  241. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  242. sqlalchemy/testing/util.py +535 -0
  243. sqlalchemy/testing/warnings.py +52 -0
  244. sqlalchemy/types.py +76 -0
  245. sqlalchemy/util/__init__.py +157 -0
  246. sqlalchemy/util/_collections.py +693 -0
  247. sqlalchemy/util/_collections_cy.cp313-win_arm64.pyd +0 -0
  248. sqlalchemy/util/_collections_cy.pxd +8 -0
  249. sqlalchemy/util/_collections_cy.py +516 -0
  250. sqlalchemy/util/_has_cython.py +46 -0
  251. sqlalchemy/util/_immutabledict_cy.cp313-win_arm64.pyd +0 -0
  252. sqlalchemy/util/_immutabledict_cy.py +240 -0
  253. sqlalchemy/util/compat.py +287 -0
  254. sqlalchemy/util/concurrency.py +322 -0
  255. sqlalchemy/util/cython.py +79 -0
  256. sqlalchemy/util/deprecations.py +401 -0
  257. sqlalchemy/util/langhelpers.py +2256 -0
  258. sqlalchemy/util/preloaded.py +152 -0
  259. sqlalchemy/util/queue.py +304 -0
  260. sqlalchemy/util/tool_support.py +201 -0
  261. sqlalchemy/util/topological.py +120 -0
  262. sqlalchemy/util/typing.py +711 -0
  263. sqlalchemy-2.1.0b1.dist-info/METADATA +267 -0
  264. sqlalchemy-2.1.0b1.dist-info/RECORD +267 -0
  265. sqlalchemy-2.1.0b1.dist-info/WHEEL +5 -0
  266. sqlalchemy-2.1.0b1.dist-info/licenses/LICENSE +19 -0
  267. sqlalchemy-2.1.0b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1667 @@
1
+ # ext/asyncio/scoping.py
2
+ # Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3
+ # <see AUTHORS file>
4
+ #
5
+ # This module is part of SQLAlchemy and is released under
6
+ # the MIT License: https://www.opensource.org/licenses/mit-license.php
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+ from typing import Callable
12
+ from typing import Generic
13
+ from typing import Iterable
14
+ from typing import Iterator
15
+ from typing import Optional
16
+ from typing import overload
17
+ from typing import Sequence
18
+ from typing import Tuple
19
+ from typing import Type
20
+ from typing import TYPE_CHECKING
21
+ from typing import TypeVar
22
+ from typing import Union
23
+
24
+ from .session import _AS
25
+ from .session import async_sessionmaker
26
+ from .session import AsyncSession
27
+ from ... import exc as sa_exc
28
+ from ... import util
29
+ from ...orm.session import Session
30
+ from ...util import create_proxy_methods
31
+ from ...util import ScopedRegistry
32
+ from ...util import warn
33
+ from ...util import warn_deprecated
34
+ from ...util.typing import TupleAny
35
+ from ...util.typing import TypeVarTuple
36
+ from ...util.typing import Unpack
37
+
38
+ if TYPE_CHECKING:
39
+ from .engine import AsyncConnection
40
+ from .result import AsyncResult
41
+ from .result import AsyncScalarResult
42
+ from .session import AsyncSessionTransaction
43
+ from ...engine import Connection
44
+ from ...engine import Engine
45
+ from ...engine import Result
46
+ from ...engine import Row
47
+ from ...engine import RowMapping
48
+ from ...engine.interfaces import _CoreAnyExecuteParams
49
+ from ...engine.interfaces import CoreExecuteOptionsParameter
50
+ from ...engine.result import ScalarResult
51
+ from ...orm._typing import _IdentityKeyType
52
+ from ...orm._typing import _O
53
+ from ...orm._typing import OrmExecuteOptionsParameter
54
+ from ...orm.interfaces import ORMOption
55
+ from ...orm.session import _BindArguments
56
+ from ...orm.session import _EntityBindKey
57
+ from ...orm.session import _PKIdentityArgument
58
+ from ...orm.session import _SessionBind
59
+ from ...sql.base import Executable
60
+ from ...sql.elements import ClauseElement
61
+ from ...sql.selectable import ForUpdateParameter
62
+ from ...sql.selectable import TypedReturnsRows
63
+
64
+ _T = TypeVar("_T", bound=Any)
65
+ _Ts = TypeVarTuple("_Ts")
66
+
67
+
68
+ @create_proxy_methods(
69
+ AsyncSession,
70
+ ":class:`_asyncio.AsyncSession`",
71
+ ":class:`_asyncio.scoping.async_scoped_session`",
72
+ classmethods=["close_all", "object_session", "identity_key"],
73
+ methods=[
74
+ "__contains__",
75
+ "__iter__",
76
+ "aclose",
77
+ "add",
78
+ "add_all",
79
+ "begin",
80
+ "begin_nested",
81
+ "close",
82
+ "reset",
83
+ "commit",
84
+ "connection",
85
+ "delete",
86
+ "delete_all",
87
+ "execute",
88
+ "expire",
89
+ "expire_all",
90
+ "expunge",
91
+ "expunge_all",
92
+ "flush",
93
+ "get_bind",
94
+ "is_modified",
95
+ "invalidate",
96
+ "merge",
97
+ "merge_all",
98
+ "refresh",
99
+ "rollback",
100
+ "scalar",
101
+ "scalars",
102
+ "get",
103
+ "get_one",
104
+ "stream",
105
+ "stream_scalars",
106
+ ],
107
+ attributes=[
108
+ "bind",
109
+ "dirty",
110
+ "deleted",
111
+ "new",
112
+ "identity_map",
113
+ "is_active",
114
+ "autoflush",
115
+ "no_autoflush",
116
+ "info",
117
+ "execution_options",
118
+ ],
119
+ use_intermediate_variable=["get"],
120
+ )
121
+ class async_scoped_session(Generic[_AS]):
122
+ """Provides scoped management of :class:`.AsyncSession` objects.
123
+
124
+ See the section :ref:`asyncio_scoped_session` for usage details.
125
+
126
+ .. versionadded:: 1.4.19
127
+
128
+
129
+ """
130
+
131
+ _support_async = True
132
+
133
+ session_factory: async_sessionmaker[_AS]
134
+ """The `session_factory` provided to `__init__` is stored in this
135
+ attribute and may be accessed at a later time. This can be useful when
136
+ a new non-scoped :class:`.AsyncSession` is needed."""
137
+
138
+ registry: ScopedRegistry[_AS]
139
+
140
+ def __init__(
141
+ self,
142
+ session_factory: async_sessionmaker[_AS],
143
+ scopefunc: Callable[[], Any],
144
+ ):
145
+ """Construct a new :class:`_asyncio.async_scoped_session`.
146
+
147
+ :param session_factory: a factory to create new :class:`_asyncio.AsyncSession`
148
+ instances. This is usually, but not necessarily, an instance
149
+ of :class:`_asyncio.async_sessionmaker`.
150
+
151
+ :param scopefunc: function which defines
152
+ the current scope. A function such as ``asyncio.current_task``
153
+ may be useful here.
154
+
155
+ """ # noqa: E501
156
+
157
+ self.session_factory = session_factory
158
+ self.registry = ScopedRegistry(session_factory, scopefunc)
159
+
160
+ @property
161
+ def _proxied(self) -> _AS:
162
+ return self.registry()
163
+
164
+ def __call__(self, **kw: Any) -> _AS:
165
+ r"""Return the current :class:`.AsyncSession`, creating it
166
+ using the :attr:`.scoped_session.session_factory` if not present.
167
+
168
+ :param \**kw: Keyword arguments will be passed to the
169
+ :attr:`.scoped_session.session_factory` callable, if an existing
170
+ :class:`.AsyncSession` is not present. If the
171
+ :class:`.AsyncSession` is present
172
+ and keyword arguments have been passed,
173
+ :exc:`~sqlalchemy.exc.InvalidRequestError` is raised.
174
+
175
+ """
176
+ if kw:
177
+ if self.registry.has():
178
+ raise sa_exc.InvalidRequestError(
179
+ "Scoped session is already present; "
180
+ "no new arguments may be specified."
181
+ )
182
+ else:
183
+ sess = self.session_factory(**kw)
184
+ self.registry.set(sess)
185
+ else:
186
+ sess = self.registry()
187
+ if not self._support_async and sess._is_asyncio:
188
+ warn_deprecated(
189
+ "Using `scoped_session` with asyncio is deprecated and "
190
+ "will raise an error in a future version. "
191
+ "Please use `async_scoped_session` instead.",
192
+ "1.4.23",
193
+ )
194
+ return sess
195
+
196
+ def configure(self, **kwargs: Any) -> None:
197
+ """reconfigure the :class:`.sessionmaker` used by this
198
+ :class:`.scoped_session`.
199
+
200
+ See :meth:`.sessionmaker.configure`.
201
+
202
+ """
203
+
204
+ if self.registry.has():
205
+ warn(
206
+ "At least one scoped session is already present. "
207
+ " configure() can not affect sessions that have "
208
+ "already been created."
209
+ )
210
+
211
+ self.session_factory.configure(**kwargs)
212
+
213
+ async def remove(self) -> None:
214
+ """Dispose of the current :class:`.AsyncSession`, if present.
215
+
216
+ Different from scoped_session's remove method, this method would use
217
+ await to wait for the close method of AsyncSession.
218
+
219
+ """
220
+
221
+ if self.registry.has():
222
+ await self.registry().close()
223
+ self.registry.clear()
224
+
225
+ # START PROXY METHODS async_scoped_session
226
+
227
+ # code within this block is **programmatically,
228
+ # statically generated** by tools/generate_proxy_methods.py
229
+
230
+ def __contains__(self, instance: object) -> bool:
231
+ r"""Return True if the instance is associated with this session.
232
+
233
+ .. container:: class_bases
234
+
235
+ Proxied for the :class:`_asyncio.AsyncSession` class on
236
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
237
+
238
+ .. container:: class_bases
239
+
240
+ Proxied for the :class:`_orm.Session` class on
241
+ behalf of the :class:`_asyncio.AsyncSession` class.
242
+
243
+ The instance may be pending or persistent within the Session for a
244
+ result of True.
245
+
246
+
247
+
248
+ """ # noqa: E501
249
+
250
+ return self._proxied.__contains__(instance)
251
+
252
+ def __iter__(self) -> Iterator[object]:
253
+ r"""Iterate over all pending or persistent instances within this
254
+ Session.
255
+
256
+ .. container:: class_bases
257
+
258
+ Proxied for the :class:`_asyncio.AsyncSession` class on
259
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
260
+
261
+ .. container:: class_bases
262
+
263
+ Proxied for the :class:`_orm.Session` class on
264
+ behalf of the :class:`_asyncio.AsyncSession` class.
265
+
266
+
267
+
268
+ """ # noqa: E501
269
+
270
+ return self._proxied.__iter__()
271
+
272
+ async def aclose(self) -> None:
273
+ r"""A synonym for :meth:`_asyncio.AsyncSession.close`.
274
+
275
+ .. container:: class_bases
276
+
277
+ Proxied for the :class:`_asyncio.AsyncSession` class on
278
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
279
+
280
+ The :meth:`_asyncio.AsyncSession.aclose` name is specifically
281
+ to support the Python standard library ``@contextlib.aclosing``
282
+ context manager function.
283
+
284
+ .. versionadded:: 2.0.20
285
+
286
+
287
+ """ # noqa: E501
288
+
289
+ return await self._proxied.aclose()
290
+
291
+ def add(self, instance: object, *, _warn: bool = True) -> None:
292
+ r"""Place an object into this :class:`_orm.Session`.
293
+
294
+ .. container:: class_bases
295
+
296
+ Proxied for the :class:`_asyncio.AsyncSession` class on
297
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
298
+
299
+ .. container:: class_bases
300
+
301
+ Proxied for the :class:`_orm.Session` class on
302
+ behalf of the :class:`_asyncio.AsyncSession` class.
303
+
304
+ Objects that are in the :term:`transient` state when passed to the
305
+ :meth:`_orm.Session.add` method will move to the
306
+ :term:`pending` state, until the next flush, at which point they
307
+ will move to the :term:`persistent` state.
308
+
309
+ Objects that are in the :term:`detached` state when passed to the
310
+ :meth:`_orm.Session.add` method will move to the :term:`persistent`
311
+ state directly.
312
+
313
+ If the transaction used by the :class:`_orm.Session` is rolled back,
314
+ objects which were transient when they were passed to
315
+ :meth:`_orm.Session.add` will be moved back to the
316
+ :term:`transient` state, and will no longer be present within this
317
+ :class:`_orm.Session`.
318
+
319
+ .. seealso::
320
+
321
+ :meth:`_orm.Session.add_all`
322
+
323
+ :ref:`session_adding` - at :ref:`session_basics`
324
+
325
+
326
+
327
+ """ # noqa: E501
328
+
329
+ return self._proxied.add(instance, _warn=_warn)
330
+
331
+ def add_all(self, instances: Iterable[object]) -> None:
332
+ r"""Add the given collection of instances to this :class:`_orm.Session`.
333
+
334
+ .. container:: class_bases
335
+
336
+ Proxied for the :class:`_asyncio.AsyncSession` class on
337
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
338
+
339
+ .. container:: class_bases
340
+
341
+ Proxied for the :class:`_orm.Session` class on
342
+ behalf of the :class:`_asyncio.AsyncSession` class.
343
+
344
+ See the documentation for :meth:`_orm.Session.add` for a general
345
+ behavioral description.
346
+
347
+ .. seealso::
348
+
349
+ :meth:`_orm.Session.add`
350
+
351
+ :ref:`session_adding` - at :ref:`session_basics`
352
+
353
+
354
+
355
+ """ # noqa: E501
356
+
357
+ return self._proxied.add_all(instances)
358
+
359
+ def begin(self) -> AsyncSessionTransaction:
360
+ r"""Return an :class:`_asyncio.AsyncSessionTransaction` object.
361
+
362
+ .. container:: class_bases
363
+
364
+ Proxied for the :class:`_asyncio.AsyncSession` class on
365
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
366
+
367
+ The underlying :class:`_orm.Session` will perform the
368
+ "begin" action when the :class:`_asyncio.AsyncSessionTransaction`
369
+ object is entered::
370
+
371
+ async with async_session.begin():
372
+ ... # ORM transaction is begun
373
+
374
+ Note that database IO will not normally occur when the session-level
375
+ transaction is begun, as database transactions begin on an
376
+ on-demand basis. However, the begin block is async to accommodate
377
+ for a :meth:`_orm.SessionEvents.after_transaction_create`
378
+ event hook that may perform IO.
379
+
380
+ For a general description of ORM begin, see
381
+ :meth:`_orm.Session.begin`.
382
+
383
+
384
+ """ # noqa: E501
385
+
386
+ return self._proxied.begin()
387
+
388
+ def begin_nested(self) -> AsyncSessionTransaction:
389
+ r"""Return an :class:`_asyncio.AsyncSessionTransaction` object
390
+ which will begin a "nested" transaction, e.g. SAVEPOINT.
391
+
392
+ .. container:: class_bases
393
+
394
+ Proxied for the :class:`_asyncio.AsyncSession` class on
395
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
396
+
397
+ Behavior is the same as that of :meth:`_asyncio.AsyncSession.begin`.
398
+
399
+ For a general description of ORM begin nested, see
400
+ :meth:`_orm.Session.begin_nested`.
401
+
402
+ .. seealso::
403
+
404
+ :ref:`aiosqlite_serializable` - special workarounds required
405
+ with the SQLite asyncio driver in order for SAVEPOINT to work
406
+ correctly.
407
+
408
+
409
+ """ # noqa: E501
410
+
411
+ return self._proxied.begin_nested()
412
+
413
+ async def close(self) -> None:
414
+ r"""Close out the transactional resources and ORM objects used by this
415
+ :class:`_asyncio.AsyncSession`.
416
+
417
+ .. container:: class_bases
418
+
419
+ Proxied for the :class:`_asyncio.AsyncSession` class on
420
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
421
+
422
+ .. seealso::
423
+
424
+ :meth:`_orm.Session.close` - main documentation for
425
+ "close"
426
+
427
+ :ref:`session_closing` - detail on the semantics of
428
+ :meth:`_asyncio.AsyncSession.close` and
429
+ :meth:`_asyncio.AsyncSession.reset`.
430
+
431
+
432
+ """ # noqa: E501
433
+
434
+ return await self._proxied.close()
435
+
436
+ async def reset(self) -> None:
437
+ r"""Close out the transactional resources and ORM objects used by this
438
+ :class:`_orm.Session`, resetting the session to its initial state.
439
+
440
+ .. container:: class_bases
441
+
442
+ Proxied for the :class:`_asyncio.AsyncSession` class on
443
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
444
+
445
+ .. versionadded:: 2.0.22
446
+
447
+ .. seealso::
448
+
449
+ :meth:`_orm.Session.reset` - main documentation for
450
+ "reset"
451
+
452
+ :ref:`session_closing` - detail on the semantics of
453
+ :meth:`_asyncio.AsyncSession.close` and
454
+ :meth:`_asyncio.AsyncSession.reset`.
455
+
456
+
457
+ """ # noqa: E501
458
+
459
+ return await self._proxied.reset()
460
+
461
+ async def commit(self) -> None:
462
+ r"""Commit the current transaction in progress.
463
+
464
+ .. container:: class_bases
465
+
466
+ Proxied for the :class:`_asyncio.AsyncSession` class on
467
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
468
+
469
+ .. seealso::
470
+
471
+ :meth:`_orm.Session.commit` - main documentation for
472
+ "commit"
473
+
474
+ """ # noqa: E501
475
+
476
+ return await self._proxied.commit()
477
+
478
+ async def connection(
479
+ self,
480
+ bind_arguments: Optional[_BindArguments] = None,
481
+ execution_options: Optional[CoreExecuteOptionsParameter] = None,
482
+ **kw: Any,
483
+ ) -> AsyncConnection:
484
+ r"""Return a :class:`_asyncio.AsyncConnection` object corresponding to
485
+ this :class:`.Session` object's transactional state.
486
+
487
+ .. container:: class_bases
488
+
489
+ Proxied for the :class:`_asyncio.AsyncSession` class on
490
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
491
+
492
+ This method may also be used to establish execution options for the
493
+ database connection used by the current transaction.
494
+
495
+ .. versionadded:: 1.4.24 Added \**kw arguments which are passed
496
+ through to the underlying :meth:`_orm.Session.connection` method.
497
+
498
+ .. seealso::
499
+
500
+ :meth:`_orm.Session.connection` - main documentation for
501
+ "connection"
502
+
503
+
504
+ """ # noqa: E501
505
+
506
+ return await self._proxied.connection(
507
+ bind_arguments=bind_arguments,
508
+ execution_options=execution_options,
509
+ **kw,
510
+ )
511
+
512
+ async def delete(self, instance: object) -> None:
513
+ r"""Mark an instance as deleted.
514
+
515
+ .. container:: class_bases
516
+
517
+ Proxied for the :class:`_asyncio.AsyncSession` class on
518
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
519
+
520
+ The database delete operation occurs upon ``flush()``.
521
+
522
+ As this operation may need to cascade along unloaded relationships,
523
+ it is awaitable to allow for those queries to take place.
524
+
525
+ .. seealso::
526
+
527
+ :meth:`_orm.Session.delete` - main documentation for delete
528
+
529
+
530
+ """ # noqa: E501
531
+
532
+ return await self._proxied.delete(instance)
533
+
534
+ async def delete_all(self, instances: Iterable[object]) -> None:
535
+ r"""Calls :meth:`.AsyncSession.delete` on multiple instances.
536
+
537
+ .. container:: class_bases
538
+
539
+ Proxied for the :class:`_asyncio.AsyncSession` class on
540
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
541
+
542
+ .. seealso::
543
+
544
+ :meth:`_orm.Session.delete_all` - main documentation for delete_all
545
+
546
+
547
+ """ # noqa: E501
548
+
549
+ return await self._proxied.delete_all(instances)
550
+
551
+ @overload
552
+ async def execute(
553
+ self,
554
+ statement: TypedReturnsRows[Unpack[_Ts]],
555
+ params: Optional[_CoreAnyExecuteParams] = None,
556
+ *,
557
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
558
+ bind_arguments: Optional[_BindArguments] = None,
559
+ _parent_execute_state: Optional[Any] = None,
560
+ _add_event: Optional[Any] = None,
561
+ ) -> Result[Unpack[_Ts]]: ...
562
+
563
+ @overload
564
+ async def execute(
565
+ self,
566
+ statement: Executable,
567
+ params: Optional[_CoreAnyExecuteParams] = None,
568
+ *,
569
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
570
+ bind_arguments: Optional[_BindArguments] = None,
571
+ _parent_execute_state: Optional[Any] = None,
572
+ _add_event: Optional[Any] = None,
573
+ ) -> Result[Unpack[TupleAny]]: ...
574
+
575
+ async def execute(
576
+ self,
577
+ statement: Executable,
578
+ params: Optional[_CoreAnyExecuteParams] = None,
579
+ *,
580
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
581
+ bind_arguments: Optional[_BindArguments] = None,
582
+ **kw: Any,
583
+ ) -> Result[Unpack[TupleAny]]:
584
+ r"""Execute a statement and return a buffered
585
+ :class:`_engine.Result` object.
586
+
587
+ .. container:: class_bases
588
+
589
+ Proxied for the :class:`_asyncio.AsyncSession` class on
590
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
591
+
592
+ .. seealso::
593
+
594
+ :meth:`_orm.Session.execute` - main documentation for execute
595
+
596
+
597
+ """ # noqa: E501
598
+
599
+ return await self._proxied.execute(
600
+ statement,
601
+ params=params,
602
+ execution_options=execution_options,
603
+ bind_arguments=bind_arguments,
604
+ **kw,
605
+ )
606
+
607
+ def expire(
608
+ self, instance: object, attribute_names: Optional[Iterable[str]] = None
609
+ ) -> None:
610
+ r"""Expire the attributes on an instance.
611
+
612
+ .. container:: class_bases
613
+
614
+ Proxied for the :class:`_asyncio.AsyncSession` class on
615
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
616
+
617
+ .. container:: class_bases
618
+
619
+ Proxied for the :class:`_orm.Session` class on
620
+ behalf of the :class:`_asyncio.AsyncSession` class.
621
+
622
+ Marks the attributes of an instance as out of date. When an expired
623
+ attribute is next accessed, a query will be issued to the
624
+ :class:`.Session` object's current transactional context in order to
625
+ load all expired attributes for the given instance. Note that
626
+ a highly isolated transaction will return the same values as were
627
+ previously read in that same transaction, regardless of changes
628
+ in database state outside of that transaction.
629
+
630
+ To expire all objects in the :class:`.Session` simultaneously,
631
+ use :meth:`Session.expire_all`.
632
+
633
+ The :class:`.Session` object's default behavior is to
634
+ expire all state whenever the :meth:`Session.rollback`
635
+ or :meth:`Session.commit` methods are called, so that new
636
+ state can be loaded for the new transaction. For this reason,
637
+ calling :meth:`Session.expire` only makes sense for the specific
638
+ case that a non-ORM SQL statement was emitted in the current
639
+ transaction.
640
+
641
+ :param instance: The instance to be refreshed.
642
+ :param attribute_names: optional list of string attribute names
643
+ indicating a subset of attributes to be expired.
644
+
645
+ .. seealso::
646
+
647
+ :ref:`session_expire` - introductory material
648
+
649
+ :meth:`.Session.expire`
650
+
651
+ :meth:`.Session.refresh`
652
+
653
+ :meth:`_orm.Query.populate_existing`
654
+
655
+
656
+
657
+ """ # noqa: E501
658
+
659
+ return self._proxied.expire(instance, attribute_names=attribute_names)
660
+
661
+ def expire_all(self) -> None:
662
+ r"""Expires all persistent instances within this Session.
663
+
664
+ .. container:: class_bases
665
+
666
+ Proxied for the :class:`_asyncio.AsyncSession` class on
667
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
668
+
669
+ .. container:: class_bases
670
+
671
+ Proxied for the :class:`_orm.Session` class on
672
+ behalf of the :class:`_asyncio.AsyncSession` class.
673
+
674
+ When any attributes on a persistent instance is next accessed,
675
+ a query will be issued using the
676
+ :class:`.Session` object's current transactional context in order to
677
+ load all expired attributes for the given instance. Note that
678
+ a highly isolated transaction will return the same values as were
679
+ previously read in that same transaction, regardless of changes
680
+ in database state outside of that transaction.
681
+
682
+ To expire individual objects and individual attributes
683
+ on those objects, use :meth:`Session.expire`.
684
+
685
+ The :class:`.Session` object's default behavior is to
686
+ expire all state whenever the :meth:`Session.rollback`
687
+ or :meth:`Session.commit` methods are called, so that new
688
+ state can be loaded for the new transaction. For this reason,
689
+ calling :meth:`Session.expire_all` is not usually needed,
690
+ assuming the transaction is isolated.
691
+
692
+ .. seealso::
693
+
694
+ :ref:`session_expire` - introductory material
695
+
696
+ :meth:`.Session.expire`
697
+
698
+ :meth:`.Session.refresh`
699
+
700
+ :meth:`_orm.Query.populate_existing`
701
+
702
+
703
+
704
+ """ # noqa: E501
705
+
706
+ return self._proxied.expire_all()
707
+
708
+ def expunge(self, instance: object) -> None:
709
+ r"""Remove the `instance` from this ``Session``.
710
+
711
+ .. container:: class_bases
712
+
713
+ Proxied for the :class:`_asyncio.AsyncSession` class on
714
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
715
+
716
+ .. container:: class_bases
717
+
718
+ Proxied for the :class:`_orm.Session` class on
719
+ behalf of the :class:`_asyncio.AsyncSession` class.
720
+
721
+ This will free all internal references to the instance. Cascading
722
+ will be applied according to the *expunge* cascade rule.
723
+
724
+
725
+
726
+ """ # noqa: E501
727
+
728
+ return self._proxied.expunge(instance)
729
+
730
+ def expunge_all(self) -> None:
731
+ r"""Remove all object instances from this ``Session``.
732
+
733
+ .. container:: class_bases
734
+
735
+ Proxied for the :class:`_asyncio.AsyncSession` class on
736
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
737
+
738
+ .. container:: class_bases
739
+
740
+ Proxied for the :class:`_orm.Session` class on
741
+ behalf of the :class:`_asyncio.AsyncSession` class.
742
+
743
+ This is equivalent to calling ``expunge(obj)`` on all objects in this
744
+ ``Session``.
745
+
746
+
747
+
748
+ """ # noqa: E501
749
+
750
+ return self._proxied.expunge_all()
751
+
752
+ async def flush(self, objects: Optional[Sequence[Any]] = None) -> None:
753
+ r"""Flush all the object changes to the database.
754
+
755
+ .. container:: class_bases
756
+
757
+ Proxied for the :class:`_asyncio.AsyncSession` class on
758
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
759
+
760
+ .. seealso::
761
+
762
+ :meth:`_orm.Session.flush` - main documentation for flush
763
+
764
+
765
+ """ # noqa: E501
766
+
767
+ return await self._proxied.flush(objects=objects)
768
+
769
+ def get_bind(
770
+ self,
771
+ mapper: Optional[_EntityBindKey[_O]] = None,
772
+ clause: Optional[ClauseElement] = None,
773
+ bind: Optional[_SessionBind] = None,
774
+ **kw: Any,
775
+ ) -> Union[Engine, Connection]:
776
+ r"""Return a "bind" to which the synchronous proxied :class:`_orm.Session`
777
+ is bound.
778
+
779
+ .. container:: class_bases
780
+
781
+ Proxied for the :class:`_asyncio.AsyncSession` class on
782
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
783
+
784
+ Unlike the :meth:`_orm.Session.get_bind` method, this method is
785
+ currently **not** used by this :class:`.AsyncSession` in any way
786
+ in order to resolve engines for requests.
787
+
788
+ .. note::
789
+
790
+ This method proxies directly to the :meth:`_orm.Session.get_bind`
791
+ method, however is currently **not** useful as an override target,
792
+ in contrast to that of the :meth:`_orm.Session.get_bind` method.
793
+ The example below illustrates how to implement custom
794
+ :meth:`_orm.Session.get_bind` schemes that work with
795
+ :class:`.AsyncSession` and :class:`.AsyncEngine`.
796
+
797
+ The pattern introduced at :ref:`session_custom_partitioning`
798
+ illustrates how to apply a custom bind-lookup scheme to a
799
+ :class:`_orm.Session` given a set of :class:`_engine.Engine` objects.
800
+ To apply a corresponding :meth:`_orm.Session.get_bind` implementation
801
+ for use with a :class:`.AsyncSession` and :class:`.AsyncEngine`
802
+ objects, continue to subclass :class:`_orm.Session` and apply it to
803
+ :class:`.AsyncSession` using
804
+ :paramref:`.AsyncSession.sync_session_class`. The inner method must
805
+ continue to return :class:`_engine.Engine` instances, which can be
806
+ acquired from a :class:`_asyncio.AsyncEngine` using the
807
+ :attr:`_asyncio.AsyncEngine.sync_engine` attribute::
808
+
809
+ # using example from "Custom Vertical Partitioning"
810
+
811
+
812
+ import random
813
+
814
+ from sqlalchemy.ext.asyncio import AsyncSession
815
+ from sqlalchemy.ext.asyncio import create_async_engine
816
+ from sqlalchemy.ext.asyncio import async_sessionmaker
817
+ from sqlalchemy.orm import Session
818
+
819
+ # construct async engines w/ async drivers
820
+ engines = {
821
+ "leader": create_async_engine("sqlite+aiosqlite:///leader.db"),
822
+ "other": create_async_engine("sqlite+aiosqlite:///other.db"),
823
+ "follower1": create_async_engine("sqlite+aiosqlite:///follower1.db"),
824
+ "follower2": create_async_engine("sqlite+aiosqlite:///follower2.db"),
825
+ }
826
+
827
+
828
+ class RoutingSession(Session):
829
+ def get_bind(self, mapper=None, clause=None, **kw):
830
+ # within get_bind(), return sync engines
831
+ if mapper and issubclass(mapper.class_, MyOtherClass):
832
+ return engines["other"].sync_engine
833
+ elif self._flushing or isinstance(clause, (Update, Delete)):
834
+ return engines["leader"].sync_engine
835
+ else:
836
+ return engines[
837
+ random.choice(["follower1", "follower2"])
838
+ ].sync_engine
839
+
840
+
841
+ # apply to AsyncSession using sync_session_class
842
+ AsyncSessionMaker = async_sessionmaker(sync_session_class=RoutingSession)
843
+
844
+ The :meth:`_orm.Session.get_bind` method is called in a non-asyncio,
845
+ implicitly non-blocking context in the same manner as ORM event hooks
846
+ and functions that are invoked via :meth:`.AsyncSession.run_sync`, so
847
+ routines that wish to run SQL commands inside of
848
+ :meth:`_orm.Session.get_bind` can continue to do so using
849
+ blocking-style code, which will be translated to implicitly async calls
850
+ at the point of invoking IO on the database drivers.
851
+
852
+
853
+ """ # noqa: E501
854
+
855
+ return self._proxied.get_bind(
856
+ mapper=mapper, clause=clause, bind=bind, **kw
857
+ )
858
+
859
+ def is_modified(
860
+ self, instance: object, include_collections: bool = True
861
+ ) -> bool:
862
+ r"""Return ``True`` if the given instance has locally
863
+ modified attributes.
864
+
865
+ .. container:: class_bases
866
+
867
+ Proxied for the :class:`_asyncio.AsyncSession` class on
868
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
869
+
870
+ .. container:: class_bases
871
+
872
+ Proxied for the :class:`_orm.Session` class on
873
+ behalf of the :class:`_asyncio.AsyncSession` class.
874
+
875
+ This method retrieves the history for each instrumented
876
+ attribute on the instance and performs a comparison of the current
877
+ value to its previously flushed or committed value, if any.
878
+
879
+ It is in effect a more expensive and accurate
880
+ version of checking for the given instance in the
881
+ :attr:`.Session.dirty` collection; a full test for
882
+ each attribute's net "dirty" status is performed.
883
+
884
+ E.g.::
885
+
886
+ return session.is_modified(someobject)
887
+
888
+ A few caveats to this method apply:
889
+
890
+ * Instances present in the :attr:`.Session.dirty` collection may
891
+ report ``False`` when tested with this method. This is because
892
+ the object may have received change events via attribute mutation,
893
+ thus placing it in :attr:`.Session.dirty`, but ultimately the state
894
+ is the same as that loaded from the database, resulting in no net
895
+ change here.
896
+ * Scalar attributes may not have recorded the previously set
897
+ value when a new value was applied, if the attribute was not loaded,
898
+ or was expired, at the time the new value was received - in these
899
+ cases, the attribute is assumed to have a change, even if there is
900
+ ultimately no net change against its database value. SQLAlchemy in
901
+ most cases does not need the "old" value when a set event occurs, so
902
+ it skips the expense of a SQL call if the old value isn't present,
903
+ based on the assumption that an UPDATE of the scalar value is
904
+ usually needed, and in those few cases where it isn't, is less
905
+ expensive on average than issuing a defensive SELECT.
906
+
907
+ The "old" value is fetched unconditionally upon set only if the
908
+ attribute container has the ``active_history`` flag set to ``True``.
909
+ This flag is set typically for primary key attributes and scalar
910
+ object references that are not a simple many-to-one. To set this
911
+ flag for any arbitrary mapped column, use the ``active_history``
912
+ argument with :func:`.column_property`.
913
+
914
+ :param instance: mapped instance to be tested for pending changes.
915
+ :param include_collections: Indicates if multivalued collections
916
+ should be included in the operation. Setting this to ``False`` is a
917
+ way to detect only local-column based properties (i.e. scalar columns
918
+ or many-to-one foreign keys) that would result in an UPDATE for this
919
+ instance upon flush.
920
+
921
+
922
+
923
+ """ # noqa: E501
924
+
925
+ return self._proxied.is_modified(
926
+ instance, include_collections=include_collections
927
+ )
928
+
929
+ async def invalidate(self) -> None:
930
+ r"""Close this Session, using connection invalidation.
931
+
932
+ .. container:: class_bases
933
+
934
+ Proxied for the :class:`_asyncio.AsyncSession` class on
935
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
936
+
937
+ For a complete description, see :meth:`_orm.Session.invalidate`.
938
+
939
+ """ # noqa: E501
940
+
941
+ return await self._proxied.invalidate()
942
+
943
+ async def merge(
944
+ self,
945
+ instance: _O,
946
+ *,
947
+ load: bool = True,
948
+ options: Optional[Sequence[ORMOption]] = None,
949
+ ) -> _O:
950
+ r"""Copy the state of a given instance into a corresponding instance
951
+ within this :class:`_asyncio.AsyncSession`.
952
+
953
+ .. container:: class_bases
954
+
955
+ Proxied for the :class:`_asyncio.AsyncSession` class on
956
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
957
+
958
+ .. seealso::
959
+
960
+ :meth:`_orm.Session.merge` - main documentation for merge
961
+
962
+
963
+ """ # noqa: E501
964
+
965
+ return await self._proxied.merge(instance, load=load, options=options)
966
+
967
+ async def merge_all(
968
+ self,
969
+ instances: Iterable[_O],
970
+ *,
971
+ load: bool = True,
972
+ options: Optional[Sequence[ORMOption]] = None,
973
+ ) -> Sequence[_O]:
974
+ r"""Calls :meth:`.AsyncSession.merge` on multiple instances.
975
+
976
+ .. container:: class_bases
977
+
978
+ Proxied for the :class:`_asyncio.AsyncSession` class on
979
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
980
+
981
+ .. seealso::
982
+
983
+ :meth:`_orm.Session.merge_all` - main documentation for merge_all
984
+
985
+
986
+ """ # noqa: E501
987
+
988
+ return await self._proxied.merge_all(
989
+ instances, load=load, options=options
990
+ )
991
+
992
+ async def refresh(
993
+ self,
994
+ instance: object,
995
+ attribute_names: Optional[Iterable[str]] = None,
996
+ with_for_update: ForUpdateParameter = None,
997
+ ) -> None:
998
+ r"""Expire and refresh the attributes on the given instance.
999
+
1000
+ .. container:: class_bases
1001
+
1002
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1003
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1004
+
1005
+ A query will be issued to the database and all attributes will be
1006
+ refreshed with their current database value.
1007
+
1008
+ This is the async version of the :meth:`_orm.Session.refresh` method.
1009
+ See that method for a complete description of all options.
1010
+
1011
+ .. seealso::
1012
+
1013
+ :meth:`_orm.Session.refresh` - main documentation for refresh
1014
+
1015
+
1016
+ """ # noqa: E501
1017
+
1018
+ return await self._proxied.refresh(
1019
+ instance,
1020
+ attribute_names=attribute_names,
1021
+ with_for_update=with_for_update,
1022
+ )
1023
+
1024
+ async def rollback(self) -> None:
1025
+ r"""Rollback the current transaction in progress.
1026
+
1027
+ .. container:: class_bases
1028
+
1029
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1030
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1031
+
1032
+ .. seealso::
1033
+
1034
+ :meth:`_orm.Session.rollback` - main documentation for
1035
+ "rollback"
1036
+
1037
+ """ # noqa: E501
1038
+
1039
+ return await self._proxied.rollback()
1040
+
1041
+ @overload
1042
+ async def scalar(
1043
+ self,
1044
+ statement: TypedReturnsRows[_T],
1045
+ params: Optional[_CoreAnyExecuteParams] = None,
1046
+ *,
1047
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1048
+ bind_arguments: Optional[_BindArguments] = None,
1049
+ **kw: Any,
1050
+ ) -> Optional[_T]: ...
1051
+
1052
+ @overload
1053
+ async def scalar(
1054
+ self,
1055
+ statement: Executable,
1056
+ params: Optional[_CoreAnyExecuteParams] = None,
1057
+ *,
1058
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1059
+ bind_arguments: Optional[_BindArguments] = None,
1060
+ **kw: Any,
1061
+ ) -> Any: ...
1062
+
1063
+ async def scalar(
1064
+ self,
1065
+ statement: Executable,
1066
+ params: Optional[_CoreAnyExecuteParams] = None,
1067
+ *,
1068
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1069
+ bind_arguments: Optional[_BindArguments] = None,
1070
+ **kw: Any,
1071
+ ) -> Any:
1072
+ r"""Execute a statement and return a scalar result.
1073
+
1074
+ .. container:: class_bases
1075
+
1076
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1077
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1078
+
1079
+ .. seealso::
1080
+
1081
+ :meth:`_orm.Session.scalar` - main documentation for scalar
1082
+
1083
+
1084
+ """ # noqa: E501
1085
+
1086
+ return await self._proxied.scalar(
1087
+ statement,
1088
+ params=params,
1089
+ execution_options=execution_options,
1090
+ bind_arguments=bind_arguments,
1091
+ **kw,
1092
+ )
1093
+
1094
+ @overload
1095
+ async def scalars(
1096
+ self,
1097
+ statement: TypedReturnsRows[_T],
1098
+ params: Optional[_CoreAnyExecuteParams] = None,
1099
+ *,
1100
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1101
+ bind_arguments: Optional[_BindArguments] = None,
1102
+ **kw: Any,
1103
+ ) -> ScalarResult[_T]: ...
1104
+
1105
+ @overload
1106
+ async def scalars(
1107
+ self,
1108
+ statement: Executable,
1109
+ params: Optional[_CoreAnyExecuteParams] = None,
1110
+ *,
1111
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1112
+ bind_arguments: Optional[_BindArguments] = None,
1113
+ **kw: Any,
1114
+ ) -> ScalarResult[Any]: ...
1115
+
1116
+ async def scalars(
1117
+ self,
1118
+ statement: Executable,
1119
+ params: Optional[_CoreAnyExecuteParams] = None,
1120
+ *,
1121
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1122
+ bind_arguments: Optional[_BindArguments] = None,
1123
+ **kw: Any,
1124
+ ) -> ScalarResult[Any]:
1125
+ r"""Execute a statement and return scalar results.
1126
+
1127
+ .. container:: class_bases
1128
+
1129
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1130
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1131
+
1132
+ :return: a :class:`_result.ScalarResult` object
1133
+
1134
+ .. versionadded:: 1.4.24 Added :meth:`_asyncio.AsyncSession.scalars`
1135
+
1136
+ .. versionadded:: 1.4.26 Added
1137
+ :meth:`_asyncio.async_scoped_session.scalars`
1138
+
1139
+ .. seealso::
1140
+
1141
+ :meth:`_orm.Session.scalars` - main documentation for scalars
1142
+
1143
+ :meth:`_asyncio.AsyncSession.stream_scalars` - streaming version
1144
+
1145
+
1146
+ """ # noqa: E501
1147
+
1148
+ return await self._proxied.scalars(
1149
+ statement,
1150
+ params=params,
1151
+ execution_options=execution_options,
1152
+ bind_arguments=bind_arguments,
1153
+ **kw,
1154
+ )
1155
+
1156
+ async def get(
1157
+ self,
1158
+ entity: _EntityBindKey[_O],
1159
+ ident: _PKIdentityArgument,
1160
+ *,
1161
+ options: Optional[Sequence[ORMOption]] = None,
1162
+ populate_existing: bool = False,
1163
+ with_for_update: ForUpdateParameter = None,
1164
+ identity_token: Optional[Any] = None,
1165
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1166
+ ) -> Union[_O, None]:
1167
+ r"""Return an instance based on the given primary key identifier,
1168
+ or ``None`` if not found.
1169
+
1170
+ .. container:: class_bases
1171
+
1172
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1173
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1174
+
1175
+ .. seealso::
1176
+
1177
+ :meth:`_orm.Session.get` - main documentation for get
1178
+
1179
+
1180
+
1181
+ """ # noqa: E501
1182
+
1183
+ result = await self._proxied.get(
1184
+ entity,
1185
+ ident,
1186
+ options=options,
1187
+ populate_existing=populate_existing,
1188
+ with_for_update=with_for_update,
1189
+ identity_token=identity_token,
1190
+ execution_options=execution_options,
1191
+ )
1192
+ return result
1193
+
1194
+ async def get_one(
1195
+ self,
1196
+ entity: _EntityBindKey[_O],
1197
+ ident: _PKIdentityArgument,
1198
+ *,
1199
+ options: Optional[Sequence[ORMOption]] = None,
1200
+ populate_existing: bool = False,
1201
+ with_for_update: ForUpdateParameter = None,
1202
+ identity_token: Optional[Any] = None,
1203
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1204
+ ) -> _O:
1205
+ r"""Return an instance based on the given primary key identifier,
1206
+ or raise an exception if not found.
1207
+
1208
+ .. container:: class_bases
1209
+
1210
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1211
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1212
+
1213
+ Raises :class:`_exc.NoResultFound` if the query selects no rows.
1214
+
1215
+ ..versionadded: 2.0.22
1216
+
1217
+ .. seealso::
1218
+
1219
+ :meth:`_orm.Session.get_one` - main documentation for get_one
1220
+
1221
+
1222
+ """ # noqa: E501
1223
+
1224
+ return await self._proxied.get_one(
1225
+ entity,
1226
+ ident,
1227
+ options=options,
1228
+ populate_existing=populate_existing,
1229
+ with_for_update=with_for_update,
1230
+ identity_token=identity_token,
1231
+ execution_options=execution_options,
1232
+ )
1233
+
1234
+ @overload
1235
+ async def stream(
1236
+ self,
1237
+ statement: TypedReturnsRows[Unpack[_Ts]],
1238
+ params: Optional[_CoreAnyExecuteParams] = None,
1239
+ *,
1240
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1241
+ bind_arguments: Optional[_BindArguments] = None,
1242
+ **kw: Any,
1243
+ ) -> AsyncResult[Unpack[_Ts]]: ...
1244
+
1245
+ @overload
1246
+ async def stream(
1247
+ self,
1248
+ statement: Executable,
1249
+ params: Optional[_CoreAnyExecuteParams] = None,
1250
+ *,
1251
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1252
+ bind_arguments: Optional[_BindArguments] = None,
1253
+ **kw: Any,
1254
+ ) -> AsyncResult[Unpack[TupleAny]]: ...
1255
+
1256
+ async def stream(
1257
+ self,
1258
+ statement: Executable,
1259
+ params: Optional[_CoreAnyExecuteParams] = None,
1260
+ *,
1261
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1262
+ bind_arguments: Optional[_BindArguments] = None,
1263
+ **kw: Any,
1264
+ ) -> AsyncResult[Unpack[TupleAny]]:
1265
+ r"""Execute a statement and return a streaming
1266
+ :class:`_asyncio.AsyncResult` object.
1267
+
1268
+ .. container:: class_bases
1269
+
1270
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1271
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1272
+
1273
+
1274
+ """ # noqa: E501
1275
+
1276
+ return await self._proxied.stream(
1277
+ statement,
1278
+ params=params,
1279
+ execution_options=execution_options,
1280
+ bind_arguments=bind_arguments,
1281
+ **kw,
1282
+ )
1283
+
1284
+ @overload
1285
+ async def stream_scalars(
1286
+ self,
1287
+ statement: TypedReturnsRows[_T],
1288
+ params: Optional[_CoreAnyExecuteParams] = None,
1289
+ *,
1290
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1291
+ bind_arguments: Optional[_BindArguments] = None,
1292
+ **kw: Any,
1293
+ ) -> AsyncScalarResult[_T]: ...
1294
+
1295
+ @overload
1296
+ async def stream_scalars(
1297
+ self,
1298
+ statement: Executable,
1299
+ params: Optional[_CoreAnyExecuteParams] = None,
1300
+ *,
1301
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1302
+ bind_arguments: Optional[_BindArguments] = None,
1303
+ **kw: Any,
1304
+ ) -> AsyncScalarResult[Any]: ...
1305
+
1306
+ async def stream_scalars(
1307
+ self,
1308
+ statement: Executable,
1309
+ params: Optional[_CoreAnyExecuteParams] = None,
1310
+ *,
1311
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1312
+ bind_arguments: Optional[_BindArguments] = None,
1313
+ **kw: Any,
1314
+ ) -> AsyncScalarResult[Any]:
1315
+ r"""Execute a statement and return a stream of scalar results.
1316
+
1317
+ .. container:: class_bases
1318
+
1319
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1320
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1321
+
1322
+ :return: an :class:`_asyncio.AsyncScalarResult` object
1323
+
1324
+ .. versionadded:: 1.4.24
1325
+
1326
+ .. seealso::
1327
+
1328
+ :meth:`_orm.Session.scalars` - main documentation for scalars
1329
+
1330
+ :meth:`_asyncio.AsyncSession.scalars` - non streaming version
1331
+
1332
+
1333
+ """ # noqa: E501
1334
+
1335
+ return await self._proxied.stream_scalars(
1336
+ statement,
1337
+ params=params,
1338
+ execution_options=execution_options,
1339
+ bind_arguments=bind_arguments,
1340
+ **kw,
1341
+ )
1342
+
1343
+ @property
1344
+ def bind(self) -> Any:
1345
+ r"""Proxy for the :attr:`_asyncio.AsyncSession.bind` attribute
1346
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1347
+
1348
+ """ # noqa: E501
1349
+
1350
+ return self._proxied.bind
1351
+
1352
+ @bind.setter
1353
+ def bind(self, attr: Any) -> None:
1354
+ self._proxied.bind = attr
1355
+
1356
+ @property
1357
+ def dirty(self) -> Any:
1358
+ r"""The set of all persistent instances considered dirty.
1359
+
1360
+ .. container:: class_bases
1361
+
1362
+ Proxied for the :class:`_asyncio.AsyncSession` class
1363
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1364
+
1365
+ .. container:: class_bases
1366
+
1367
+ Proxied for the :class:`_orm.Session` class
1368
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1369
+
1370
+ E.g.::
1371
+
1372
+ some_mapped_object in session.dirty
1373
+
1374
+ Instances are considered dirty when they were modified but not
1375
+ deleted.
1376
+
1377
+ Note that this 'dirty' calculation is 'optimistic'; most
1378
+ attribute-setting or collection modification operations will
1379
+ mark an instance as 'dirty' and place it in this set, even if
1380
+ there is no net change to the attribute's value. At flush
1381
+ time, the value of each attribute is compared to its
1382
+ previously saved value, and if there's no net change, no SQL
1383
+ operation will occur (this is a more expensive operation so
1384
+ it's only done at flush time).
1385
+
1386
+ To check if an instance has actionable net changes to its
1387
+ attributes, use the :meth:`.Session.is_modified` method.
1388
+
1389
+
1390
+
1391
+ """ # noqa: E501
1392
+
1393
+ return self._proxied.dirty
1394
+
1395
+ @property
1396
+ def deleted(self) -> Any:
1397
+ r"""The set of all instances marked as 'deleted' within this ``Session``
1398
+
1399
+ .. container:: class_bases
1400
+
1401
+ Proxied for the :class:`_asyncio.AsyncSession` class
1402
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1403
+
1404
+ .. container:: class_bases
1405
+
1406
+ Proxied for the :class:`_orm.Session` class
1407
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1408
+
1409
+
1410
+ """ # noqa: E501
1411
+
1412
+ return self._proxied.deleted
1413
+
1414
+ @property
1415
+ def new(self) -> Any:
1416
+ r"""The set of all instances marked as 'new' within this ``Session``.
1417
+
1418
+ .. container:: class_bases
1419
+
1420
+ Proxied for the :class:`_asyncio.AsyncSession` class
1421
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1422
+
1423
+ .. container:: class_bases
1424
+
1425
+ Proxied for the :class:`_orm.Session` class
1426
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1427
+
1428
+
1429
+ """ # noqa: E501
1430
+
1431
+ return self._proxied.new
1432
+
1433
+ @property
1434
+ def identity_map(self) -> Any:
1435
+ r"""Proxy for the :attr:`_orm.Session.identity_map` attribute
1436
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1437
+
1438
+ .. container:: class_bases
1439
+
1440
+ Proxied for the :class:`_asyncio.AsyncSession` class
1441
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1442
+
1443
+
1444
+ """ # noqa: E501
1445
+
1446
+ return self._proxied.identity_map
1447
+
1448
+ @identity_map.setter
1449
+ def identity_map(self, attr: Any) -> None:
1450
+ self._proxied.identity_map = attr
1451
+
1452
+ @property
1453
+ def is_active(self) -> Any:
1454
+ r"""True if this :class:`.Session` not in "partial rollback" state.
1455
+
1456
+ .. container:: class_bases
1457
+
1458
+ Proxied for the :class:`_asyncio.AsyncSession` class
1459
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1460
+
1461
+ .. container:: class_bases
1462
+
1463
+ Proxied for the :class:`_orm.Session` class
1464
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1465
+
1466
+ .. versionchanged:: 1.4 The :class:`_orm.Session` no longer begins
1467
+ a new transaction immediately, so this attribute will be False
1468
+ when the :class:`_orm.Session` is first instantiated.
1469
+
1470
+ "partial rollback" state typically indicates that the flush process
1471
+ of the :class:`_orm.Session` has failed, and that the
1472
+ :meth:`_orm.Session.rollback` method must be emitted in order to
1473
+ fully roll back the transaction.
1474
+
1475
+ If this :class:`_orm.Session` is not in a transaction at all, the
1476
+ :class:`_orm.Session` will autobegin when it is first used, so in this
1477
+ case :attr:`_orm.Session.is_active` will return True.
1478
+
1479
+ Otherwise, if this :class:`_orm.Session` is within a transaction,
1480
+ and that transaction has not been rolled back internally, the
1481
+ :attr:`_orm.Session.is_active` will also return True.
1482
+
1483
+ .. seealso::
1484
+
1485
+ :ref:`faq_session_rollback`
1486
+
1487
+ :meth:`_orm.Session.in_transaction`
1488
+
1489
+
1490
+
1491
+ """ # noqa: E501
1492
+
1493
+ return self._proxied.is_active
1494
+
1495
+ @property
1496
+ def autoflush(self) -> Any:
1497
+ r"""Proxy for the :attr:`_orm.Session.autoflush` attribute
1498
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1499
+
1500
+ .. container:: class_bases
1501
+
1502
+ Proxied for the :class:`_asyncio.AsyncSession` class
1503
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1504
+
1505
+
1506
+ """ # noqa: E501
1507
+
1508
+ return self._proxied.autoflush
1509
+
1510
+ @autoflush.setter
1511
+ def autoflush(self, attr: Any) -> None:
1512
+ self._proxied.autoflush = attr
1513
+
1514
+ @property
1515
+ def no_autoflush(self) -> Any:
1516
+ r"""Return a context manager that disables autoflush.
1517
+
1518
+ .. container:: class_bases
1519
+
1520
+ Proxied for the :class:`_asyncio.AsyncSession` class
1521
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1522
+
1523
+ .. container:: class_bases
1524
+
1525
+ Proxied for the :class:`_orm.Session` class
1526
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1527
+
1528
+ e.g.::
1529
+
1530
+ with session.no_autoflush:
1531
+
1532
+ some_object = SomeClass()
1533
+ session.add(some_object)
1534
+ # won't autoflush
1535
+ some_object.related_thing = session.query(SomeRelated).first()
1536
+
1537
+ Operations that proceed within the ``with:`` block
1538
+ will not be subject to flushes occurring upon query
1539
+ access. This is useful when initializing a series
1540
+ of objects which involve existing database queries,
1541
+ where the uncompleted object should not yet be flushed.
1542
+
1543
+
1544
+
1545
+ """ # noqa: E501
1546
+
1547
+ return self._proxied.no_autoflush
1548
+
1549
+ @property
1550
+ def info(self) -> Any:
1551
+ r"""A user-modifiable dictionary.
1552
+
1553
+ .. container:: class_bases
1554
+
1555
+ Proxied for the :class:`_asyncio.AsyncSession` class
1556
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1557
+
1558
+ .. container:: class_bases
1559
+
1560
+ Proxied for the :class:`_orm.Session` class
1561
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1562
+
1563
+ The initial value of this dictionary can be populated using the
1564
+ ``info`` argument to the :class:`.Session` constructor or
1565
+ :class:`.sessionmaker` constructor or factory methods. The dictionary
1566
+ here is always local to this :class:`.Session` and can be modified
1567
+ independently of all other :class:`.Session` objects.
1568
+
1569
+
1570
+
1571
+ """ # noqa: E501
1572
+
1573
+ return self._proxied.info
1574
+
1575
+ @property
1576
+ def execution_options(self) -> Any:
1577
+ r"""Proxy for the :attr:`_orm.Session.execution_options` attribute
1578
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1579
+
1580
+ .. container:: class_bases
1581
+
1582
+ Proxied for the :class:`_asyncio.AsyncSession` class
1583
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1584
+
1585
+
1586
+ """ # noqa: E501
1587
+
1588
+ return self._proxied.execution_options
1589
+
1590
+ @execution_options.setter
1591
+ def execution_options(self, attr: Any) -> None:
1592
+ self._proxied.execution_options = attr
1593
+
1594
+ @classmethod
1595
+ async def close_all(cls) -> None:
1596
+ r"""Close all :class:`_asyncio.AsyncSession` sessions.
1597
+
1598
+ .. container:: class_bases
1599
+
1600
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1601
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1602
+
1603
+ .. deprecated:: 2.0 The :meth:`.AsyncSession.close_all` method is deprecated and will be removed in a future release. Please refer to :func:`_asyncio.close_all_sessions`.
1604
+
1605
+ """ # noqa: E501
1606
+
1607
+ return await AsyncSession.close_all()
1608
+
1609
+ @classmethod
1610
+ def object_session(cls, instance: object) -> Optional[Session]:
1611
+ r"""Return the :class:`.Session` to which an object belongs.
1612
+
1613
+ .. container:: class_bases
1614
+
1615
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1616
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1617
+
1618
+ .. container:: class_bases
1619
+
1620
+ Proxied for the :class:`_orm.Session` class on
1621
+ behalf of the :class:`_asyncio.AsyncSession` class.
1622
+
1623
+ This is an alias of :func:`.object_session`.
1624
+
1625
+
1626
+
1627
+ """ # noqa: E501
1628
+
1629
+ return AsyncSession.object_session(instance)
1630
+
1631
+ @classmethod
1632
+ def identity_key(
1633
+ cls,
1634
+ class_: Optional[Type[Any]] = None,
1635
+ ident: Union[Any, Tuple[Any, ...]] = None,
1636
+ *,
1637
+ instance: Optional[Any] = None,
1638
+ row: Optional[Union[Row[Unpack[TupleAny]], RowMapping]] = None,
1639
+ identity_token: Optional[Any] = None,
1640
+ ) -> _IdentityKeyType[Any]:
1641
+ r"""Return an identity key.
1642
+
1643
+ .. container:: class_bases
1644
+
1645
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1646
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1647
+
1648
+ .. container:: class_bases
1649
+
1650
+ Proxied for the :class:`_orm.Session` class on
1651
+ behalf of the :class:`_asyncio.AsyncSession` class.
1652
+
1653
+ This is an alias of :func:`.util.identity_key`.
1654
+
1655
+
1656
+
1657
+ """ # noqa: E501
1658
+
1659
+ return AsyncSession.identity_key(
1660
+ class_=class_,
1661
+ ident=ident,
1662
+ instance=instance,
1663
+ row=row,
1664
+ identity_token=identity_token,
1665
+ )
1666
+
1667
+ # END PROXY METHODS async_scoped_session