-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when query data before asyncio.gather() #452
Comments
Any solution for this one? @router.post("/path")
async def generic_method(mysql_driver: Database = Depends(get_mysql_driver)):
async with mysql_driver.transaction():
some_data = {"a": "b"}
await generic_save_method(mysql_driver, some_data)
tasks = []
for i in range(0,10):
# both method are declared with async def another_generic_method1/2
if i % 2 == 0:
tasks.append(another_generic_save_method1(mysql_drive, i))
else:
tasks.append(another_generic_save_method2(mysql_drive, i))
result = await asyncio.gather(*tasks) Even if I have a option to create a workaround with batch save and call something like below, I would like to know how to fix the above batch_for_one = []
batch_for_two = []
for i in range(0,10):
if i % 2 == 0:
batch_for_one.append(i)
else:
batch_for_two.append(i)
await save_batch_for_generic_method1(mysql_drive, batch_for_one)
await save_batch_for_generic_method2(mysql_drive, batch_for_two)
# I think would be greate to be abe to do sth like:
# await asyncio.gather(save_batch_for_generic_method1(mysql_drive, batch_for_one),save_batch_for_generic_method2(mysql_drive, batch_for_two))
# but I think we'll run again in the same issue. I didn't tested this but it sounds like the same, I proffered the above version.
# The query in batch is the one with INSERT ... VALUES (generic_value), (another_generic_value), (so_on_value) Edit: |
ContextVars aren't handled all that carefully in current releases. I might have solved this for you in #546 |
code
error
The
ContextVar
is set whenawait database.fetch_all(query)
, causing both Tasks to share aContextVar
is there any solution(reset
ContextVar
value?)?The text was updated successfully, but these errors were encountered: