From 82b2d064be09335ace4c4d2b02b14568664abd4a Mon Sep 17 00:00:00 2001 From: Yair Silbermintz Date: Wed, 1 Dec 2021 12:51:52 -0500 Subject: [PATCH 1/5] Support Django 4.0 Replace calls to deprecated methods Fix test config & Replace additional methods removed in django 4.0 Update tox for official Django 4 release --- .github/workflows/tests.yml | 8 +++++++- graphene_django/tests/urls.py | 6 +++--- graphene_django/tests/urls_inherited.py | 4 ++-- graphene_django/tests/urls_pretty.py | 4 ++-- tox.ini | 12 ++++++++---- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2dbf8229f..c63742a7b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,13 @@ jobs: matrix: django: ["2.2", "3.0", "3.1", "3.2"] python-version: ["3.6", "3.7", "3.8", "3.9"] - + include: + - django: "3.2" + python-version: "3.10" + - django: "4.0" + python-version: "3.10" + - django: "main" + python-version: "3.10" steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/graphene_django/tests/urls.py b/graphene_django/tests/urls.py index 66b3fc4d2..f2faae2bd 100644 --- a/graphene_django/tests/urls.py +++ b/graphene_django/tests/urls.py @@ -1,8 +1,8 @@ -from django.conf.urls import url +from django.urls import re_path from ..views import GraphQLView urlpatterns = [ - url(r"^graphql/batch", GraphQLView.as_view(batch=True)), - url(r"^graphql", GraphQLView.as_view(graphiql=True)), + re_path(r"^graphql/batch", GraphQLView.as_view(batch=True)), + re_path(r"^graphql", GraphQLView.as_view(graphiql=True)), ] diff --git a/graphene_django/tests/urls_inherited.py b/graphene_django/tests/urls_inherited.py index 6fa801916..815d04db8 100644 --- a/graphene_django/tests/urls_inherited.py +++ b/graphene_django/tests/urls_inherited.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.urls import re_path from ..views import GraphQLView from .schema_view import schema @@ -10,4 +10,4 @@ class CustomGraphQLView(GraphQLView): pretty = True -urlpatterns = [url(r"^graphql/inherited/$", CustomGraphQLView.as_view())] +urlpatterns = [re_path(r"^graphql/inherited/$", CustomGraphQLView.as_view())] diff --git a/graphene_django/tests/urls_pretty.py b/graphene_django/tests/urls_pretty.py index 1133c870f..635d4f390 100644 --- a/graphene_django/tests/urls_pretty.py +++ b/graphene_django/tests/urls_pretty.py @@ -1,6 +1,6 @@ -from django.conf.urls import url +from django.urls import re_path from ..views import GraphQLView from .schema_view import schema -urlpatterns = [url(r"^graphql", GraphQLView.as_view(schema=schema, pretty=True))] +urlpatterns = [re_path(r"^graphql", GraphQLView.as_view(schema=schema, pretty=True))] diff --git a/tox.ini b/tox.ini index 7128afe09..fc89ce94a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,8 @@ [tox] envlist = - py{36,37,38,39}-django{22,30,31,32,main}, + py{36,37,38,39}-django{22,30,31}, + py{36,37,38,39,310}-django32, + py{38,39,310}-django{40,main}, black,flake8 [gh-actions] @@ -9,6 +11,7 @@ python = 3.7: py37 3.8: py38 3.9: py39 + 3.10: py310 [gh-actions:env] DJANGO = @@ -16,6 +19,7 @@ DJANGO = 3.0: django30 3.1: django31 3.2: django32 + 4.0: django40 main: djangomain [testenv] @@ -26,13 +30,13 @@ setenv = deps = -e.[test] psycopg2-binary - django20: Django>=2.0,<2.1 - django21: Django>=2.1,<2.2 django22: Django>=2.2,<3.0 - django30: Django>=3.0a1,<3.1 + django30: Django>=3.0,<3.1 django31: Django>=3.1,<3.2 django32: Django>=3.2a1,<3.3 djangomain: https://github.com/django/django/archive/main.zip + django32: Django>=3.2,<4.0 + django40: Django>=4.0,<4.1 commands = {posargs:py.test --cov=graphene_django graphene_django examples} [testenv:black] From e584d5ef5d56cd3f1fdaaca9d8897f04326ed471 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Wed, 8 Dec 2021 18:51:38 -0600 Subject: [PATCH 2/5] Handle deprecation warning for requires_system_checks. This is being removed in django 4.1 --- graphene_django/management/commands/graphql_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_django/management/commands/graphql_schema.py b/graphene_django/management/commands/graphql_schema.py index 565f5d8e1..41654305f 100644 --- a/graphene_django/management/commands/graphql_schema.py +++ b/graphene_django/management/commands/graphql_schema.py @@ -48,7 +48,7 @@ def add_arguments(self, parser): class Command(CommandArguments): help = "Dump Graphene schema as a JSON or GraphQL file" can_import_settings = True - requires_system_checks = False + requires_system_checks = [] def save_json_file(self, out, schema_dict, indent): with open(out, "w") as outfile: From c6c122b9733495d7dde122052f3a91391865a7e5 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Wed, 8 Dec 2021 18:58:16 -0600 Subject: [PATCH 3/5] Support Python 3.10's new format_exception signature. --- graphene_django/debug/exception/formating.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_django/debug/exception/formating.py b/graphene_django/debug/exception/formating.py index ed7ebabf3..0d477b330 100644 --- a/graphene_django/debug/exception/formating.py +++ b/graphene_django/debug/exception/formating.py @@ -11,7 +11,7 @@ def wrap_exception(exception): exc_type=force_str(type(exception)), stack="".join( traceback.format_exception( - etype=type(exception), value=exception, tb=exception.__traceback__ + exception, value=exception, tb=exception.__traceback__ ) ), ) From ae01931ad33200088ab5840eadfcc374e69f3aad Mon Sep 17 00:00:00 2001 From: tschilling Date: Sun, 12 Dec 2021 10:50:10 -0600 Subject: [PATCH 4/5] Clean up tox.ini file. --- tox.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index fc89ce94a..d65839a79 100644 --- a/tox.ini +++ b/tox.ini @@ -33,10 +33,9 @@ deps = django22: Django>=2.2,<3.0 django30: Django>=3.0,<3.1 django31: Django>=3.1,<3.2 - django32: Django>=3.2a1,<3.3 - djangomain: https://github.com/django/django/archive/main.zip django32: Django>=3.2,<4.0 django40: Django>=4.0,<4.1 + djangomain: https://github.com/django/django/archive/main.zip commands = {posargs:py.test --cov=graphene_django graphene_django examples} [testenv:black] From c2818c85e005502a35e0ee16ec976ec33f29aa5d Mon Sep 17 00:00:00 2001 From: tschilling Date: Sun, 12 Dec 2021 11:18:37 -0600 Subject: [PATCH 5/5] Switch from re_path to path. The DEFAULT_GRAPHQL_URL had to change because it doesn't take into account the APPEND_SLASH setting from within Django. --- README.md | 2 +- docs/authorization.rst | 2 +- graphene_django/tests/urls.py | 6 +++--- graphene_django/tests/urls_inherited.py | 4 ++-- graphene_django/tests/urls_pretty.py | 4 ++-- graphene_django/utils/testing.py | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5045e787a..6f06ccc2b 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ from graphene_django.views import GraphQLView urlpatterns = [ # ... - path('graphql', GraphQLView.as_view(graphiql=True)), + path('graphql/', GraphQLView.as_view(graphiql=True)), ] ``` diff --git a/docs/authorization.rst b/docs/authorization.rst index 39305f6b1..bc88cdac5 100644 --- a/docs/authorization.rst +++ b/docs/authorization.rst @@ -198,7 +198,7 @@ For Django 2.2 and above: urlpatterns = [ # some other urls - path('graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)), + path('graphql/', PrivateGraphQLView.as_view(graphiql=True, schema=schema)), ] .. _LoginRequiredMixin: https://docs.djangoproject.com/en/dev/topics/auth/default/#the-loginrequired-mixin diff --git a/graphene_django/tests/urls.py b/graphene_django/tests/urls.py index f2faae2bd..3702ce5cf 100644 --- a/graphene_django/tests/urls.py +++ b/graphene_django/tests/urls.py @@ -1,8 +1,8 @@ -from django.urls import re_path +from django.urls import path from ..views import GraphQLView urlpatterns = [ - re_path(r"^graphql/batch", GraphQLView.as_view(batch=True)), - re_path(r"^graphql", GraphQLView.as_view(graphiql=True)), + path("graphql/batch", GraphQLView.as_view(batch=True)), + path("graphql", GraphQLView.as_view(graphiql=True)), ] diff --git a/graphene_django/tests/urls_inherited.py b/graphene_django/tests/urls_inherited.py index 815d04db8..1e65da0a5 100644 --- a/graphene_django/tests/urls_inherited.py +++ b/graphene_django/tests/urls_inherited.py @@ -1,4 +1,4 @@ -from django.urls import re_path +from django.urls import path from ..views import GraphQLView from .schema_view import schema @@ -10,4 +10,4 @@ class CustomGraphQLView(GraphQLView): pretty = True -urlpatterns = [re_path(r"^graphql/inherited/$", CustomGraphQLView.as_view())] +urlpatterns = [path("graphql/inherited/", CustomGraphQLView.as_view())] diff --git a/graphene_django/tests/urls_pretty.py b/graphene_django/tests/urls_pretty.py index 635d4f390..62759347b 100644 --- a/graphene_django/tests/urls_pretty.py +++ b/graphene_django/tests/urls_pretty.py @@ -1,6 +1,6 @@ -from django.urls import re_path +from django.urls import path from ..views import GraphQLView from .schema_view import schema -urlpatterns = [re_path(r"^graphql", GraphQLView.as_view(schema=schema, pretty=True))] +urlpatterns = [path("graphql", GraphQLView.as_view(schema=schema, pretty=True))] diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 763196dc5..b91a02f36 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -3,7 +3,7 @@ from django.test import Client, TestCase, TransactionTestCase -DEFAULT_GRAPHQL_URL = "/graphql/" +DEFAULT_GRAPHQL_URL = "/graphql" def graphql_query(