Skip to content

Commit a64a608

Browse files
committed
sync scripts: Use asyncio.run instead of get_event_loop
Replace the asyncio.get_event_loop() followed by run_until_complete(...) call with the asyncio.run(...), because it makes the code cleaner and works even if the event loop in the main thread has been cleared. This fixes an issue with pytest-asyncio 0.25.2 which seems to clear the main thread event loop sometimes. The tests on sync_attachments and sync_objects used to fail if all tests were ran in the same pytest call, but if only those sync tests are selected (e.g. with `pytest -k test_sync`) then the tests used to pass. After this change they seem to pass on both cases. This might be the same issue as described in [1] (even if it is only for Python 3.9, but our issue happens with Python 3.12) or not. [1] pytest-dev/pytest-asyncio#1039
1 parent c85cf25 commit a64a608

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/passari_workflow/scripts/sync_attachments.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ async def sync_attachments(offset=0, limit=None, save_progress=False):
223223
def cli(offset, limit, save_progress):
224224
connect_db()
225225

226-
loop = asyncio.get_event_loop()
227-
loop.run_until_complete(
226+
asyncio.run(
228227
sync_attachments(
229228
offset=offset, limit=limit, save_progress=save_progress
230229
)

src/passari_workflow/scripts/sync_objects.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ async def sync_objects(offset=0, limit=None, save_progress=False):
221221
def cli(offset, limit, save_progress):
222222
connect_db()
223223

224-
loop = asyncio.get_event_loop()
225-
loop.run_until_complete(
224+
asyncio.run(
226225
sync_objects(
227226
offset=offset, limit=limit, save_progress=save_progress
228227
)

0 commit comments

Comments
 (0)