Ticket #31380: async-unsafe.diff

File async-unsafe.diff, 2.2 KB (added by hashlash, 5 years ago)

Check DJANGO_ALLOW_ASYNC_UNSAFE on deployment implementation

  • django/core/checks/__init__.py

    diff --git a/django/core/checks/__init__.py b/django/core/checks/__init__.py
    index ededae38ba..b987af7bf5 100644
    a b from .messages import (  
    55from .registry import Tags, register, run_checks, tag_exists
    66
    77# Import these to force registration of checks
     8import django.core.checks.asyncio  # NOQA isort:skip
    89import django.core.checks.caches  # NOQA isort:skip
    910import django.core.checks.database  # NOQA isort:skip
    1011import django.core.checks.model_checks  # NOQA isort:skip
  • new file django/core/checks/asyncio.py

    diff --git a/django/core/checks/asyncio.py b/django/core/checks/asyncio.py
    new file mode 100644
    index 0000000000..2063481bd6
    - +  
     1import os
     2
     3from . import Error, Tags, register
     4
     5E001 = 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)
     13def check_async_unsafe(app_configs, **kwargs):
     14    if os.environ.get('DJANGO_ALLOW_ASYNC_UNSAFE'):
     15        return [E001]
     16    return []
  • django/core/checks/registry.py

    diff --git a/django/core/checks/registry.py b/django/core/checks/registry.py
    index 74359db586..f81a0197f9 100644
    a b class Tags:  
    88    Built-in tags for internal checks.
    99    """
    1010    admin = 'admin'
     11    asyncio = 'asyncio'
    1112    caches = 'caches'
    1213    compatibility = 'compatibility'
    1314    database = 'database'
  • new file tests/check_framework/test_asyncio.py

    diff --git a/tests/check_framework/test_asyncio.py b/tests/check_framework/test_asyncio.py
    new file mode 100644
    index 0000000000..5158d29b49
    - +  
     1import os
     2from unittest import mock
     3
     4from django.core.checks import asyncio
     5from django.test import SimpleTestCase
     6
     7
     8class 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])
Back to Top