eat: add Django 2 compatibility

This commit is contained in:
Thomas Leonard 2023-07-31 06:16:48 +00:00 committed by Laurent Riviere
parent 047810fe9a
commit 3e0a36216f
6 changed files with 23 additions and 13 deletions

View File

@ -14,6 +14,12 @@ jobs:
django: ["3.2", "4.1", "4.2"]
python-version: ["3.8", "3.9", "3.10"]
include:
- django: "2.2"
python-version: "3.10"
- django: "2.2"
python-version: "3.11"
- django: "3.2"
python-version: "3.11"
- django: "4.1"
python-version: "3.11"
- django: "4.2"

View File

@ -1,9 +1,3 @@
# For backwards compatibility, we import JSONField to have it available for import via
# this compat module (https://github.com/graphql-python/graphene-django/issues/1428).
# Django's JSONField is available in Django 3.2+ (the minimum version we support)
from django.db.models import JSONField
class MissingType:
def __init__(self, *args, **kwargs):
pass
@ -18,5 +12,12 @@ try:
IntegerRangeField,
RangeField,
)
try:
from django.db.models import JSONField
except ImportError:
from django.contrib.postgres.fields import JSONField
except ImportError:
IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 4
IntegerRangeField, ArrayField, HStoreField, RangeField, JSONField = (
MissingType,
) * 5

View File

@ -37,7 +37,7 @@ except ImportError:
from graphql import assert_valid_name as assert_name
from graphql.pyutils import register_description
from .compat import ArrayField, HStoreField, RangeField
from .compat import ArrayField, HStoreField, RangeField, JSONField
from .fields import DjangoConnectionField, DjangoListField
from .settings import graphene_settings
from .utils.str_converters import to_const
@ -474,7 +474,7 @@ def convert_postgres_array_to_list(field, registry=None):
@convert_django_field.register(HStoreField)
@convert_django_field.register(models.JSONField)
@convert_django_field.register(JSONField)
def convert_json_field_to_string(field, registry=None):
return JSONString(
description=get_django_field_description(field), required=not field.null

View File

@ -11,7 +11,7 @@ from pytest import raises
import graphene
from graphene.relay import Node
from ..compat import IntegerRangeField, MissingType
from ..compat import IntegerRangeField, MissingType, JSONField
from ..fields import DjangoConnectionField
from ..types import DjangoObjectType
from ..utils import DJANGO_FILTER_INSTALLED
@ -133,7 +133,7 @@ def test_should_query_postgres_fields():
class Event(models.Model):
ages = IntegerRangeField(help_text="The age ranges")
data = models.JSONField(help_text="Data")
data = JSONField(help_text="Data")
store = HStoreField()
tags = ArrayField(models.CharField(max_length=50))

View File

@ -20,7 +20,7 @@ tests_require = [
"coveralls",
"mock",
"pytz",
"django-filter>=22.1",
"django-filter>=21.1",
"pytest-django>=4.5.2",
] + rest_framework_require
@ -62,7 +62,7 @@ setup(
"graphene @ git+https://github.com/graphql-python/graphene.git@ee1ff975d71f6590eb6933d76d12054c9839774a#egg=graphene",
"graphql-core>=3.1.0,<4",
"graphql-relay @ git+https://github.com/loft-orbital/graphql-relay-py.git@loft-v3.2.0-1#egg=graphql-relay",
"Django>=3.2",
"Django>=2.2.13",
"promise>=2.1",
"text-unidecode",
],

View File

@ -1,5 +1,6 @@
[tox]
envlist =
py{38,39,310}-django22
py{38,39,310}-django32
py{38,39}-django{41,42}
py{310,311}-django{41,42,main}
@ -14,6 +15,7 @@ python =
[gh-actions:env]
DJANGO =
2.2: django22
3.2: django32
4.1: django41
4.2: django42
@ -28,6 +30,7 @@ setenv =
deps =
-e.[test]
psycopg2-binary
django22: Django==2.2.13
django32: Django>=3.2,<4.0
django41: Django>=4.1,<4.2
django42: Django>=4.2,<4.3