Skip to content

Commit 2a46eea

Browse files
committed
Don't enter a transaction in MockOSDBMixin when starting a request
In OpenSearch we're currently not using transactions. To accurately mock this with the MySQL backend we instead enter a transaction in each method call.
1 parent 4d40913 commit 2a46eea

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

diracx-testing/src/diracx/testing/mock_osdb.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,22 @@ async def client_context(self) -> AsyncIterator[None]:
7272
yield
7373

7474
async def __aenter__(self):
75-
await self._sql_db.__aenter__()
75+
"""Enter the request context.
76+
77+
This is a no-op as the real OpenSearch class doesn't use transactions.
78+
Instead we enter a transaction in each method that needs it.
79+
"""
7680
return self
7781

7882
async def __aexit__(self, exc_type, exc_value, traceback):
79-
await self._sql_db.__aexit__(exc_type, exc_value, traceback)
83+
pass
8084

8185
async def create_index_template(self) -> None:
8286
async with self._sql_db.engine.begin() as conn:
8387
await conn.run_sync(self._sql_db.metadata.create_all)
8488

8589
async def upsert(self, doc_id, document) -> None:
86-
async with self:
90+
async with self._sql_db:
8791
values = {}
8892
for key, value in document.items():
8993
if key in self.fields:
@@ -106,7 +110,7 @@ async def search(
106110
per_page: int = 100,
107111
page: int | None = None,
108112
) -> tuple[int, list[dict[Any, Any]]]:
109-
async with self:
113+
async with self._sql_db:
110114
# Apply selection
111115
if parameters:
112116
columns = []
@@ -150,7 +154,8 @@ async def search(
150154
return results
151155

152156
async def ping(self):
153-
return await self._sql_db.ping()
157+
async with self._sql_db:
158+
return await self._sql_db.ping()
154159

155160

156161
def fake_available_osdb_implementations(name, *, real_available_implementations):

0 commit comments

Comments
 (0)