-
Notifications
You must be signed in to change notification settings - Fork 993
Sync/Async issues when integrating with Django 3.1.5 #439
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
Comments
The documentation is pointing about not using it in the application, not in testing, in testing it is fine also the env var should be configured in a |
But I am using it in an application, not in testing. So this is why using |
@caramdache thanks for the report. It looks like the SQL business is annotated with the Playwright's sync API uses asyncio loop internally, it uses greenlets to simulate blocking synchronous behavior, but still runs the event loop inside. So django is getting confused. I'll see if we can do something about it. But the nature of the check suggests that it is a development-time assertion. If you know that you only hit this from within Playwright, it is probably fine to disable the check. Having said that, if you disable it and bring in more code into your project you might miss a real offender. |
Closing for now since the workaround seems working. |
Clarify why we set "DJANGO_ALLOW_ASYNC_UNSAFE", see: microsoft/playwright-python#439 (comment)
Clarify why we set "DJANGO_ALLOW_ASYNC_UNSAFE", see: microsoft/playwright-python#439 (comment)
Just wondering if this is still the official advice. I've just started trying to use Playwright (completely new to it) in a Django 5 project and encountered the |
I'm currently converting some puppeteer code to playright-python. And I'm taking this opportunity to use my django models rather than raw SQL queries:
However, I'm running into some issues and I would appreciate some guidance:
SomeModelClass.objects.get(pk=1)
, I get the following error:django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
sync_to_async
, from https://docs.djangoproject.com/en/3.1/topics/async/#asgiref.sync.sync_to_async. But this leads to further errors.This seemed to work, but at the expense of code complexity and I starting running into timeout issues.
But, as pointed out by django, it may result in data loss.
Any advice from the team?
The text was updated successfully, but these errors were encountered: