diff --git a/django/core/checks/__init__.py b/django/core/checks/__init__.py
index ededae38ba..b987af7bf5 100644
|
a
|
b
|
from .messages import (
|
| 5 | 5 | from .registry import Tags, register, run_checks, tag_exists |
| 6 | 6 | |
| 7 | 7 | # Import these to force registration of checks |
| | 8 | import django.core.checks.asyncio # NOQA isort:skip |
| 8 | 9 | import django.core.checks.caches # NOQA isort:skip |
| 9 | 10 | import django.core.checks.database # NOQA isort:skip |
| 10 | 11 | import django.core.checks.model_checks # NOQA isort:skip |
diff --git a/django/core/checks/asyncio.py b/django/core/checks/asyncio.py
new file mode 100644
index 0000000000..2063481bd6
|
-
|
+
|
|
| | 1 | import os |
| | 2 | |
| | 3 | from . import Error, Tags, register |
| | 4 | |
| | 5 | E001 = Error( |
| | 6 | "You must not set DJANGO_ALLOW_ASYNC_UNSAFE in your " |
| | 7 | "deployment environment variable", |
| | 8 | id='asyncio.E001', |
| | 9 | ) |
| | 10 | |
| | 11 | |
| | 12 | @register(Tags.asyncio, deploy=True) |
| | 13 | def check_async_unsafe(app_configs, **kwargs): |
| | 14 | if os.environ.get('DJANGO_ALLOW_ASYNC_UNSAFE'): |
| | 15 | return [E001] |
| | 16 | return [] |
diff --git a/django/core/checks/registry.py b/django/core/checks/registry.py
index 74359db586..f81a0197f9 100644
|
a
|
b
|
class Tags:
|
| 8 | 8 | Built-in tags for internal checks. |
| 9 | 9 | """ |
| 10 | 10 | admin = 'admin' |
| | 11 | asyncio = 'asyncio' |
| 11 | 12 | caches = 'caches' |
| 12 | 13 | compatibility = 'compatibility' |
| 13 | 14 | database = 'database' |
diff --git a/tests/check_framework/test_asyncio.py b/tests/check_framework/test_asyncio.py
new file mode 100644
index 0000000000..5158d29b49
|
-
|
+
|
|
| | 1 | import os |
| | 2 | from unittest import mock |
| | 3 | |
| | 4 | from django.core.checks import asyncio |
| | 5 | from django.test import SimpleTestCase |
| | 6 | |
| | 7 | |
| | 8 | class CheckAsynchronousSafetyTest(SimpleTestCase): |
| | 9 | @property |
| | 10 | def func(self): |
| | 11 | from django.core.checks.asyncio import check_async_unsafe |
| | 12 | return check_async_unsafe |
| | 13 | |
| | 14 | @mock.patch.dict(os.environ, {'DJANGO_ALLOW_ASYNC_UNSAFE': 'true'}) |
| | 15 | def test_not_allowed_async_unsafe(self): |
| | 16 | self.assertEqual(self.func(None), [asyncio.E001]) |