jararaca 0.3.12a15__py3-none-any.whl → 0.3.12a16__py3-none-any.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.
Potentially problematic release.
This version of jararaca might be problematic. Click here for more details.
- jararaca/persistence/interceptors/aiosqa_interceptor.py +70 -27
- {jararaca-0.3.12a15.dist-info → jararaca-0.3.12a16.dist-info}/METADATA +1 -1
- {jararaca-0.3.12a15.dist-info → jararaca-0.3.12a16.dist-info}/RECORD +7 -7
- pyproject.toml +1 -1
- {jararaca-0.3.12a15.dist-info → jararaca-0.3.12a16.dist-info}/LICENSE +0 -0
- {jararaca-0.3.12a15.dist-info → jararaca-0.3.12a16.dist-info}/WHEEL +0 -0
- {jararaca-0.3.12a15.dist-info → jararaca-0.3.12a16.dist-info}/entry_points.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from contextlib import asynccontextmanager, contextmanager, suppress
|
|
2
2
|
from contextvars import ContextVar
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from typing import Any, AsyncGenerator, Generator
|
|
4
|
+
from typing import Any, AsyncGenerator, Generator, Protocol
|
|
5
5
|
|
|
6
6
|
from sqlalchemy.ext.asyncio import (
|
|
7
7
|
AsyncSession,
|
|
@@ -18,6 +18,42 @@ from jararaca.persistence.interceptors.decorators import (
|
|
|
18
18
|
)
|
|
19
19
|
from jararaca.reflect.metadata import get_metadata_value
|
|
20
20
|
|
|
21
|
+
|
|
22
|
+
class SessionManager(Protocol):
|
|
23
|
+
def spawn_session(self, connection_name: str | None = None) -> AsyncSession: ...
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
ctx_session_manager: ContextVar[SessionManager | None] = ContextVar(
|
|
27
|
+
"ctx_session_manager", default=None
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@contextmanager
|
|
32
|
+
def providing_session_manager(
|
|
33
|
+
session_manager: SessionManager,
|
|
34
|
+
) -> Generator[None, Any, None]:
|
|
35
|
+
"""
|
|
36
|
+
Context manager to provide a session manager for the current context.
|
|
37
|
+
"""
|
|
38
|
+
token = ctx_session_manager.set(session_manager)
|
|
39
|
+
try:
|
|
40
|
+
yield
|
|
41
|
+
finally:
|
|
42
|
+
with suppress(ValueError):
|
|
43
|
+
ctx_session_manager.reset(token)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def use_session_manager() -> SessionManager:
|
|
47
|
+
"""
|
|
48
|
+
Retrieve the current session manager from the context variable.
|
|
49
|
+
Raises ValueError if no session manager is set.
|
|
50
|
+
"""
|
|
51
|
+
session_manager = ctx_session_manager.get()
|
|
52
|
+
if session_manager is None:
|
|
53
|
+
raise ValueError("No session manager set in the context.")
|
|
54
|
+
return session_manager
|
|
55
|
+
|
|
56
|
+
|
|
21
57
|
ctx_default_connection_name: ContextVar[str] = ContextVar(
|
|
22
58
|
"ctx_default_connection_name", default=DEFAULT_CONNECTION_NAME
|
|
23
59
|
)
|
|
@@ -71,7 +107,8 @@ async def providing_new_session(
|
|
|
71
107
|
connection_name: str | None = None,
|
|
72
108
|
) -> AsyncGenerator[AsyncSession, None]:
|
|
73
109
|
|
|
74
|
-
|
|
110
|
+
session_manager = use_session_manager()
|
|
111
|
+
current_session = session_manager.spawn_session(connection_name)
|
|
75
112
|
|
|
76
113
|
async with AsyncSession(
|
|
77
114
|
current_session.bind,
|
|
@@ -131,7 +168,7 @@ class AIOSQAConfig:
|
|
|
131
168
|
self.inject_default = inject_default
|
|
132
169
|
|
|
133
170
|
|
|
134
|
-
class AIOSqlAlchemySessionInterceptor(AppInterceptor):
|
|
171
|
+
class AIOSqlAlchemySessionInterceptor(AppInterceptor, SessionManager):
|
|
135
172
|
|
|
136
173
|
def __init__(self, config: AIOSQAConfig):
|
|
137
174
|
self.config = config
|
|
@@ -148,27 +185,33 @@ class AIOSqlAlchemySessionInterceptor(AppInterceptor):
|
|
|
148
185
|
self, app_context: AppTransactionContext
|
|
149
186
|
) -> AsyncGenerator[None, None]:
|
|
150
187
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
188
|
+
with providing_session_manager(self):
|
|
189
|
+
uses_connection_metadata = get_metadata_value(
|
|
190
|
+
INJECT_PERSISTENCE_SESSION_METADATA_TEMPLATE.format(
|
|
191
|
+
connection_name=self.config.connection_name
|
|
192
|
+
),
|
|
193
|
+
self.config.inject_default,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
if not uses_connection_metadata:
|
|
197
|
+
yield
|
|
198
|
+
return
|
|
199
|
+
|
|
200
|
+
async with self.sessionmaker() as session, session.begin() as tx:
|
|
201
|
+
token = ctx_default_connection_name.set(self.config.connection_name)
|
|
202
|
+
with providing_session(session, tx, self.config.connection_name):
|
|
203
|
+
try:
|
|
204
|
+
yield
|
|
205
|
+
if tx.is_active:
|
|
206
|
+
await tx.commit()
|
|
207
|
+
except Exception as e:
|
|
208
|
+
await tx.rollback()
|
|
209
|
+
raise e
|
|
210
|
+
finally:
|
|
211
|
+
with suppress(ValueError):
|
|
212
|
+
ctx_default_connection_name.reset(token)
|
|
213
|
+
|
|
214
|
+
def spawn_session(self, connection_name: str | None = None) -> AsyncSession:
|
|
215
|
+
connection_name = ensure_name(connection_name)
|
|
216
|
+
session = self.sessionmaker()
|
|
217
|
+
return session
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
2
2
|
README.md,sha256=2qMM__t_MoLKZr4IY9tXjo-Jn6LKjuHMb1qbyXpgL08,3401
|
|
3
|
-
pyproject.toml,sha256=
|
|
3
|
+
pyproject.toml,sha256=CJhUE0Llc5_AlQo4FUo5kjI7cblJBlzu4-YmrIZ0QCQ,2041
|
|
4
4
|
jararaca/__init__.py,sha256=vK3zyIVLckwZgj1FPX6jzSbzaSWmSy3wQ2KMwmpJnmg,22046
|
|
5
5
|
jararaca/__main__.py,sha256=-O3vsB5lHdqNFjUtoELDF81IYFtR-DSiiFMzRaiSsv4,67
|
|
6
6
|
jararaca/broker_backend/__init__.py,sha256=GzEIuHR1xzgCJD4FE3harNjoaYzxHMHoEL0_clUaC-k,3528
|
|
@@ -32,7 +32,7 @@ jararaca/observability/providers/otel.py,sha256=8N1F32W43t7c8cwmtTh6Yz9b7HyfGFSR
|
|
|
32
32
|
jararaca/persistence/base.py,sha256=xnGUbsLNz3gO-9iJt-Sn5NY13Yc9-misP8wLwQuGGoM,1024
|
|
33
33
|
jararaca/persistence/exports.py,sha256=Ghx4yoFaB4QVTb9WxrFYgmcSATXMNvrOvT8ybPNKXCA,62
|
|
34
34
|
jararaca/persistence/interceptors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
|
-
jararaca/persistence/interceptors/aiosqa_interceptor.py,sha256=
|
|
35
|
+
jararaca/persistence/interceptors/aiosqa_interceptor.py,sha256=Cvr8wtCpRHE1Ddy9NvlZvXE2EVV0jBIibHCqj4pRkvc,6689
|
|
36
36
|
jararaca/persistence/interceptors/constants.py,sha256=o8g5RxDX9dSSnM9eXYlTJalGPfWxYm6-CAA8-FooUzE,36
|
|
37
37
|
jararaca/persistence/interceptors/decorators.py,sha256=p37r9ux5w_bvn8xPNPhScl3fjCc2enqTR0cJYLxMsrI,1627
|
|
38
38
|
jararaca/persistence/session.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -74,8 +74,8 @@ jararaca/tools/typescript/interface_parser.py,sha256=OMvz4vcsKD0eYPwH1hd3PJpLP2B
|
|
|
74
74
|
jararaca/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
75
75
|
jararaca/utils/rabbitmq_utils.py,sha256=ytdAFUyv-OBkaVnxezuJaJoLrmN7giZgtKeet_IsMBs,10918
|
|
76
76
|
jararaca/utils/retry.py,sha256=DzPX_fXUvTqej6BQ8Mt2dvLo9nNlTBm7Kx2pFZ26P2Q,4668
|
|
77
|
-
jararaca-0.3.
|
|
78
|
-
jararaca-0.3.
|
|
79
|
-
jararaca-0.3.
|
|
80
|
-
jararaca-0.3.
|
|
81
|
-
jararaca-0.3.
|
|
77
|
+
jararaca-0.3.12a16.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
78
|
+
jararaca-0.3.12a16.dist-info/METADATA,sha256=d5M-tdj2etlzLG_d1OofoaoDIFYwLqgyhHda36VMTJU,4996
|
|
79
|
+
jararaca-0.3.12a16.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
80
|
+
jararaca-0.3.12a16.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
|
|
81
|
+
jararaca-0.3.12a16.dist-info/RECORD,,
|
pyproject.toml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|