diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2019-12-02 13:02:21 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-12-03 17:50:24 +0100 |
| commit | 9243435b5e7e327d0e1e1271b6dfd4c74ca7120b (patch) | |
| tree | 428fb4f5231e176d251a1df3ecd345bab2611ade /django | |
| parent | 45de0c299bfc8117b04bb47df61a676a5013c4ce (diff) | |
[3.0.x] Fixed #31056 -- Allowed disabling async-unsafe check with an environment variable.
Backport of c90ab30fa1305481024b9c3c50b5a6ed6cd9a2f5 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/asyncio.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/django/utils/asyncio.py b/django/utils/asyncio.py index c4de04ba12..2405e3413e 100644 --- a/django/utils/asyncio.py +++ b/django/utils/asyncio.py @@ -1,5 +1,6 @@ import asyncio import functools +import os from django.core.exceptions import SynchronousOnlyOperation @@ -12,14 +13,15 @@ def async_unsafe(message): def decorator(func): @functools.wraps(func) def inner(*args, **kwargs): - # Detect a running event loop in this thread. - try: - event_loop = asyncio.get_event_loop() - except RuntimeError: - pass - else: - if event_loop.is_running(): - raise SynchronousOnlyOperation(message) + if not os.environ.get('DJANGO_ALLOW_ASYNC_UNSAFE'): + # Detect a running event loop in this thread. + try: + event_loop = asyncio.get_event_loop() + except RuntimeError: + pass + else: + if event_loop.is_running(): + raise SynchronousOnlyOperation(message) # Pass onwards. return func(*args, **kwargs) return inner |
