Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Switch to Django 3.1, add support for ASGI
Patryk Zawadzkif1b8a012146f
diff --git a/poetry.lock b/poetry.lockindex dddfce24de..b0fa612add 100644--- a/poetry.lock+++ b/poetry.lock@@ -416,10 +416,10 @@ description = "A high-level Python Web framework that encourages rapid developmename = "django"optional = falsepython-versions = ">=3.6"-version = "3.0.8"+version = "3.1"[package.dependencies]-asgiref = ">=3.2,<4.0"+asgiref = ">=3.2.10,<3.3.0"pytz = "*"sqlparse = ">=0.2.2"@@ -2309,6 +2309,7 @@ multidict = ">=4.0"[metadata]content-hash = "2c29f431ea93ee7ee63e10a7bf479b983b00e2979557e643e4e2e08cabca71f3"+lock-version = "1.0"python-versions = "~3.8"[metadata.files]@@ -2507,8 +2508,8 @@ dj-email-url = [{file = "dj_email_url-1.0.1-py2.py3-none-any.whl", hash = "sha256:557c07b3039befdc1c561c4038b155d659c09f996d5e33c91189c2e23969da90"},]django = [- {file = "Django-3.0.8-py3-none-any.whl", hash = "sha256:5457fc953ec560c5521b41fad9e6734a4668b7ba205832191bbdff40ec61073c"},- {file = "Django-3.0.8.tar.gz", hash = "sha256:31a5fbbea5fc71c99e288ec0b2f00302a0a92c44b13ede80b73a6a4d6d205582"},+ {file = "Django-3.1-py3-none-any.whl", hash = "sha256:1a63f5bb6ff4d7c42f62a519edc2adbb37f9b78068a5a862beff858b68e3dc8b"},+ {file = "Django-3.1.tar.gz", hash = "sha256:2d390268a13c655c97e0e2ede9d117007996db692c1bb93eabebd4fb7ea7012b"},]django-appconf = [{file = "django-appconf-1.0.4.tar.gz", hash = "sha256:be58deb54a43d77d2e1621fe59f787681376d3cd0b8bd8e4758ef6c3a6453380"},@@ -2838,11 +2839,6 @@ markupsafe = [{file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6"},{file = "MarkupSafe-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2"},{file = "MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c"},- {file = "MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15"},- {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2"},- {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42"},- {file = "MarkupSafe-1.1.1-cp38-cp38-win32.whl", hash = "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b"},- {file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"},{file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"},]maxminddb = [diff --git a/requirements.txt b/requirements.txtindex ae49f2006d..4a2a3b57ca 100644--- a/requirements.txt+++ b/requirements.txt@@ -5,13 +5,13 @@ asgiref==3.2.10babel==2.8.0beautifulsoup4==4.7.1billiard==3.6.3.0-boto3==1.14.28-botocore==1.17.28-braintree==4.2.0+boto3==1.14.35+botocore==1.17.35+braintree==4.3.0cachetools==4.1.1cairocffi==1.1.0cairosvg==2.4.2-celery==4.4.6+celery==4.4.7certifi==2020.6.20cffi==1.14.0chardet==3.0.4@@ -19,7 +19,7 @@ cssselect2==0.3.0defusedxml==0.6.0dj-database-url==0.5.0dj-email-url==1.0.1-django==3.0.8+django==3.1django-appconf==1.0.4django-cache-url==3.1.2django-countries==6.1.2@@ -42,7 +42,6 @@ enmerkar==0.7.1et-xmlfile==1.0.1faker==4.1.1freezegun==0.3.15-future==0.18.2google-api-core==1.21.0google-auth==1.19.1google-cloud-core==1.3.0@@ -67,7 +66,7 @@ jsonfield==3.1.0kombu==4.6.11lxml==4.5.2markdown==3.2.2-maxminddb==2.0.1+maxminddb==2.0.2maxminddb-geolite2==2018.703measurement==3.2.0mpmath==1.1.0@@ -111,7 +110,7 @@ threadloop==1.0.2thrift==0.13.0tinycss2==1.0.2tornado==6.0.4-tqdm==4.48.0+tqdm==4.48.1typing==3.7.4.3unidecode==1.1.1urllib3==1.25.9diff --git a/requirements_dev.txt b/requirements_dev.txtindex 143d524b84..676a4d85be 100644--- a/requirements_dev.txt+++ b/requirements_dev.txt@@ -12,13 +12,13 @@ beautifulsoup4==4.7.1beautifultable==0.7.0billiard==3.6.3.0black==19.10b0-boto3==1.14.28-botocore==1.17.28-braintree==4.2.0+boto3==1.14.35+botocore==1.17.35+braintree==4.3.0cachetools==4.1.1cairocffi==1.1.0cairosvg==2.4.2-celery==4.4.6+celery==4.4.7certifi==2020.6.20cffi==1.14.0cfgv==3.1.0@@ -32,7 +32,7 @@ defusedxml==0.6.0distlib==0.3.1dj-database-url==0.5.0dj-email-url==1.0.1-django==3.0.8+django==3.1django-appconf==1.0.4django-cache-url==3.1.2django-countries==6.1.2@@ -63,7 +63,6 @@ faker==4.1.1filelock==3.0.12flake8==3.8.3freezegun==0.3.15-future==0.18.2gitdb==4.0.5gitpython==3.1.7google-api-core==1.21.0@@ -84,6 +83,7 @@ html-to-draftjs==1.0.1html5lib==1.1identify==1.4.23idna==2.10+iniconfig==1.0.1isort==4.3.21jaeger-client==4.3.0jdcal==1.4.1@@ -95,7 +95,7 @@ lazy-object-proxy==1.4.3lxml==4.5.2markdown==3.2.2markupsafe==1.1.1-maxminddb==2.0.1+maxminddb==2.0.2maxminddb-geolite2==2018.703mccabe==0.6.1measurement==3.2.0@@ -134,14 +134,14 @@ pylint-django==2.2.0pylint-plugin-utils==0.6pyparsing==2.4.7pyphen==0.9.5-pytest==5.4.3+pytest==6.0.1pytest-cov==2.10.0pytest-django==3.9.0pytest-django-queries==1.1.0pytest-forked==1.2.0pytest-mock==3.2.0pytest-vcr==1.0.2-pytest-xdist==1.33.0+pytest-xdist==1.34.0python-dateutil==2.8.1python-json-logger==0.1.11python-magic==0.4.18@@ -173,8 +173,8 @@ thrift==0.13.0tinycss2==1.0.2toml==0.10.1tornado==6.0.4-tox==3.18.0-tqdm==4.48.0+tox==3.18.1+tqdm==4.48.1transifex-client==0.13.11typed-ast==1.4.1typing==3.7.4.3@@ -185,7 +185,6 @@ uwsgi==2.0.19.1; sys_platform != "win32"vcrpy==4.0.2vine==1.3.0virtualenv==20.0.27-wcwidth==0.2.5weasyprint==51webencodings==0.5.1wrapt==1.12.1diff --git a/saleor/account/i18n.py b/saleor/account/i18n.pyindex 9d0581fa96..8f7f947937 100644--- a/saleor/account/i18n.py+++ b/saleor/account/i18n.py@@ -3,7 +3,7 @@ from collections import defaultdictimport i18naddressfrom django import formsfrom django.core.exceptions import ValidationError-from django.forms.forms import BoundField # type: ignore+from django.forms import BoundField # type: ignorefrom django_countries import countriesfrom .models import Addressdiff --git a/saleor/asgi/__init__.py b/saleor/asgi/__init__.pynew file mode 100644index 0000000000..49c8a37a5d--- /dev/null+++ b/saleor/asgi/__init__.py@@ -0,0 +1,18 @@+"""ASGI config for saleor project.++It exposes the ASGI callable as a module-level variable named ``application``.++For more information on this file, see+https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/+"""++import os++from django.core.asgi import get_asgi_application++from saleor.asgi.health_check import health_check++os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saleor.settings")++application = get_asgi_application()+application = health_check(application, "/health/")diff --git a/saleor/asgi/health_check.py b/saleor/asgi/health_check.pynew file mode 100644index 0000000000..af53223216--- /dev/null+++ b/saleor/asgi/health_check.py@@ -0,0 +1,15 @@+def health_check(application, health_url):+ async def health_check_wrapper(scope, receive, send):+ if scope.get("path") != health_url:+ await application(scope, receive, send)+ return+ await send(+ {+ "type": "http.response.start",+ "status": 200,+ "headers": [(b"content-type", b"text/plain")],+ }+ )+ await send({"type": "http.response.body"})++ return health_check_wrapperdiff --git a/saleor/graphql/account/mutations/jwt.py b/saleor/graphql/account/mutations/jwt.pyindex 6c94ff2c37..57c9bb0115 100644--- a/saleor/graphql/account/mutations/jwt.py+++ b/saleor/graphql/account/mutations/jwt.py@@ -3,7 +3,10 @@ from typing import Optionalimport grapheneimport jwtfrom django.core.exceptions import ValidationError-from django.middleware.csrf import _compare_salted_tokens, _get_new_csrf_token+from django.middleware.csrf import ( # type: ignore+ _compare_masked_tokens,+ _get_new_csrf_token,+)from django.utils import timezonefrom django.utils.crypto import get_random_stringfrom graphene.types.generic import GenericScalar@@ -180,7 +183,7 @@ class RefreshToken(BaseMutation):@classmethoddef clean_csrf_token(cls, csrf_token, payload):- is_valid = _compare_salted_tokens(csrf_token, payload["csrfToken"])+ is_valid = _compare_masked_tokens(csrf_token, payload["csrfToken"])if not is_valid:raise ValidationError({diff --git a/saleor/wsgi/__init__.py b/saleor/wsgi/__init__.pyindex 5b14dec0ee..c55b78c0b7 100644--- a/saleor/wsgi/__init__.py+++ b/saleor/wsgi/__init__.py@@ -27,13 +27,7 @@ def get_allowed_host_lazy():os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saleor.settings")-# This application object is used by any WSGI server configured to use this-# file. This includes Django's development server, if the WSGI_APPLICATION-# setting points here.application = get_wsgi_application()-# Apply WSGI middleware here.-# from helloworld.wsgi import HelloWorldApplication-# application = HelloWorldApplication(application)application = health_check(application, "/health/")# Warm-up the django application instead of letting it lazy-load