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:29:31 +0100 |
commit | c90ab30fa1305481024b9c3c50b5a6ed6cd9a2f5 (patch) | |
tree | c1178f55153aec63190c0329882a00513569e2cc /django/utils/asyncio.py | |
parent | 635a3f8e6e0303e8a87586ef6be4ab0cc01d7c0d (diff) | |
download | django-c90ab30fa1305481024b9c3c50b5a6ed6cd9a2f5.tar.gz |
Fixed #31056 -- Allowed disabling async-unsafe check with an environment variable.
Diffstat (limited to 'django/utils/asyncio.py')
-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 |