Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Switch to Django 3.1, add support for ASGI

Patryk Zawadzkif1b8a012146f
diff --git a/poetry.lock b/poetry.lock
index dddfce24de..b0fa612add 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -416,10 +416,10 @@ description = "A high-level Python Web framework that encourages rapid developme
name = "django"
optional = false
python-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.txt
index ae49f2006d..4a2a3b57ca 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,13 +5,13 @@ asgiref==3.2.10
babel==2.8.0
beautifulsoup4==4.7.1
billiard==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.0
cachetools==4.1.1
cairocffi==1.1.0
cairosvg==2.4.2
-celery==4.4.6
+celery==4.4.7
certifi==2020.6.20
cffi==1.14.0
chardet==3.0.4
@@ -19,7 +19,7 @@ cssselect2==0.3.0
defusedxml==0.6.0
dj-database-url==0.5.0
dj-email-url==1.0.1
-django==3.0.8
+django==3.1
django-appconf==1.0.4
django-cache-url==3.1.2
django-countries==6.1.2
@@ -42,7 +42,6 @@ enmerkar==0.7.1
et-xmlfile==1.0.1
faker==4.1.1
freezegun==0.3.15
-future==0.18.2
google-api-core==1.21.0
google-auth==1.19.1
google-cloud-core==1.3.0
@@ -67,7 +66,7 @@ jsonfield==3.1.0
kombu==4.6.11
lxml==4.5.2
markdown==3.2.2
-maxminddb==2.0.1
+maxminddb==2.0.2
maxminddb-geolite2==2018.703
measurement==3.2.0
mpmath==1.1.0
@@ -111,7 +110,7 @@ threadloop==1.0.2
thrift==0.13.0
tinycss2==1.0.2
tornado==6.0.4
-tqdm==4.48.0
+tqdm==4.48.1
typing==3.7.4.3
unidecode==1.1.1
urllib3==1.25.9
diff --git a/requirements_dev.txt b/requirements_dev.txt
index 143d524b84..676a4d85be 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -12,13 +12,13 @@ beautifulsoup4==4.7.1
beautifultable==0.7.0
billiard==3.6.3.0
black==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.0
cachetools==4.1.1
cairocffi==1.1.0
cairosvg==2.4.2
-celery==4.4.6
+celery==4.4.7
certifi==2020.6.20
cffi==1.14.0
cfgv==3.1.0
@@ -32,7 +32,7 @@ defusedxml==0.6.0
distlib==0.3.1
dj-database-url==0.5.0
dj-email-url==1.0.1
-django==3.0.8
+django==3.1
django-appconf==1.0.4
django-cache-url==3.1.2
django-countries==6.1.2
@@ -63,7 +63,6 @@ faker==4.1.1
filelock==3.0.12
flake8==3.8.3
freezegun==0.3.15
-future==0.18.2
gitdb==4.0.5
gitpython==3.1.7
google-api-core==1.21.0
@@ -84,6 +83,7 @@ html-to-draftjs==1.0.1
html5lib==1.1
identify==1.4.23
idna==2.10
+iniconfig==1.0.1
isort==4.3.21
jaeger-client==4.3.0
jdcal==1.4.1
@@ -95,7 +95,7 @@ lazy-object-proxy==1.4.3
lxml==4.5.2
markdown==3.2.2
markupsafe==1.1.1
-maxminddb==2.0.1
+maxminddb==2.0.2
maxminddb-geolite2==2018.703
mccabe==0.6.1
measurement==3.2.0
@@ -134,14 +134,14 @@ pylint-django==2.2.0
pylint-plugin-utils==0.6
pyparsing==2.4.7
pyphen==0.9.5
-pytest==5.4.3
+pytest==6.0.1
pytest-cov==2.10.0
pytest-django==3.9.0
pytest-django-queries==1.1.0
pytest-forked==1.2.0
pytest-mock==3.2.0
pytest-vcr==1.0.2
-pytest-xdist==1.33.0
+pytest-xdist==1.34.0
python-dateutil==2.8.1
python-json-logger==0.1.11
python-magic==0.4.18
@@ -173,8 +173,8 @@ thrift==0.13.0
tinycss2==1.0.2
toml==0.10.1
tornado==6.0.4
-tox==3.18.0
-tqdm==4.48.0
+tox==3.18.1
+tqdm==4.48.1
transifex-client==0.13.11
typed-ast==1.4.1
typing==3.7.4.3
@@ -185,7 +185,6 @@ uwsgi==2.0.19.1; sys_platform != "win32"
vcrpy==4.0.2
vine==1.3.0
virtualenv==20.0.27
-wcwidth==0.2.5
weasyprint==51
webencodings==0.5.1
wrapt==1.12.1
diff --git a/saleor/account/i18n.py b/saleor/account/i18n.py
index 9d0581fa96..8f7f947937 100644
--- a/saleor/account/i18n.py
+++ b/saleor/account/i18n.py
@@ -3,7 +3,7 @@ from collections import defaultdict
import i18naddress
from django import forms
from django.core.exceptions import ValidationError
-from django.forms.forms import BoundField # type: ignore
+from django.forms import BoundField # type: ignore
from django_countries import countries
from .models import Address
diff --git a/saleor/asgi/__init__.py b/saleor/asgi/__init__.py
new file mode 100644
index 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.py
new file mode 100644
index 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_wrapper
diff --git a/saleor/graphql/account/mutations/jwt.py b/saleor/graphql/account/mutations/jwt.py
index 6c94ff2c37..57c9bb0115 100644
--- a/saleor/graphql/account/mutations/jwt.py
+++ b/saleor/graphql/account/mutations/jwt.py
@@ -3,7 +3,10 @@ from typing import Optional
import graphene
import jwt
from 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 timezone
from django.utils.crypto import get_random_string
from graphene.types.generic import GenericScalar
@@ -180,7 +183,7 @@ class RefreshToken(BaseMutation):
@classmethod
def 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__.py
index 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