Skip to content

remove JSONField compat #1421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions graphene_django/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ def __init__(self, *args, **kwargs):
IntegerRangeField,
ArrayField,
HStoreField,
JSONField as PGJSONField,
RangeField,
)
except ImportError:
IntegerRangeField, ArrayField, HStoreField, PGJSONField, RangeField = (
MissingType,
) * 5

try:
# JSONField is only available from Django 3.1
from django.db.models import JSONField
except ImportError:
JSONField = MissingType
IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should be * 4 now instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this was merged, I added a separate quick PR for this #1423

7 changes: 3 additions & 4 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from graphql import assert_valid_name as assert_name
from graphql.pyutils import register_description

from .compat import ArrayField, HStoreField, JSONField, PGJSONField, RangeField
from .compat import ArrayField, HStoreField, RangeField
from .fields import DjangoListField, DjangoConnectionField
from .settings import graphene_settings
from .utils.str_converters import to_const
Expand Down Expand Up @@ -346,9 +346,8 @@ def convert_postgres_array_to_list(field, registry=None):


@convert_django_field.register(HStoreField)
@convert_django_field.register(PGJSONField)
@convert_django_field.register(JSONField)
def convert_pg_and_json_field_to_string(field, registry=None):
@convert_django_field.register(models.JSONField)
def convert_json_field_to_string(field, registry=None):
return JSONString(
description=get_django_field_description(field), required=not field.null
)
Expand Down
12 changes: 0 additions & 12 deletions graphene_django/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from ..compat import (
ArrayField,
HStoreField,
JSONField,
PGJSONField,
MissingType,
RangeField,
)
Expand Down Expand Up @@ -372,16 +370,6 @@ def test_should_postgres_hstore_convert_string():
assert_conversion(HStoreField, JSONString)


@pytest.mark.skipif(PGJSONField is MissingType, reason="PGJSONField should exist")
def test_should_postgres_json_convert_string():
assert_conversion(PGJSONField, JSONString)


@pytest.mark.skipif(JSONField is MissingType, reason="JSONField should exist")
def test_should_json_convert_string():
assert_conversion(JSONField, JSONString)


@pytest.mark.skipif(RangeField is MissingType, reason="RangeField should exist")
def test_should_postgres_range_convert_list():
from django.contrib.postgres.fields import IntegerRangeField
Expand Down
3 changes: 1 addition & 2 deletions graphene_django/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ def test_should_query_postgres_fields():
from django.contrib.postgres.fields import (
IntegerRangeField,
ArrayField,
JSONField,
HStoreField,
)

class Event(models.Model):
ages = IntegerRangeField(help_text="The age ranges")
data = JSONField(help_text="Data")
data = models.JSONField(help_text="Data")
store = HStoreField()
tags = ArrayField(models.CharField(max_length=50))

Expand Down