From 9fdfba45a765c4294eac07ae69b2f9713545c272 Mon Sep 17 00:00:00 2001 From: Jonathan Ehwald Date: Mon, 12 Oct 2020 00:12:17 +0200 Subject: [PATCH 01/19] Add graphene >=3.0b5 to the dependencies --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7b350c39..924b5e3b 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ requirements = [ # To keep things simple, we only support newer versions of Graphene - "graphene>=2.1.3,<3", + "graphene>=3.0b5", "promise>=2.3", # Tests fail with 1.0.19 "SQLAlchemy>=1.2,<2", From ecbedc657b0bf1fd449352c891aefd71cfe84382 Mon Sep 17 00:00:00 2001 From: Jonathan Ehwald Date: Mon, 12 Oct 2020 00:13:12 +0200 Subject: [PATCH 02/19] Remove backend usage from the benchmark tests --- graphene_sqlalchemy/tests/test_benchmark.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/graphene_sqlalchemy/tests/test_benchmark.py b/graphene_sqlalchemy/tests/test_benchmark.py index 1e5ee4f1..8d8a111f 100644 --- a/graphene_sqlalchemy/tests/test_benchmark.py +++ b/graphene_sqlalchemy/tests/test_benchmark.py @@ -1,6 +1,4 @@ import pytest -from graphql.backend import GraphQLCachedBackend, GraphQLCoreBackend - import graphene from graphene import relay @@ -47,15 +45,12 @@ def resolve_reporters(self, info): def benchmark_query(session_factory, benchmark, query): schema = get_schema() - cached_backend = GraphQLCachedBackend(GraphQLCoreBackend()) - cached_backend.document_from_string(schema, query) # Prime cache @benchmark def execute_query(): result = schema.execute( query, context_value={"session": session_factory()}, - backend=cached_backend, ) assert not result.errors From 1c486e8bee14a6e61a543fa92212b6705035ad45 Mon Sep 17 00:00:00 2001 From: Jonathan Ehwald Date: Tue, 5 Jan 2021 18:38:25 +0100 Subject: [PATCH 03/19] Make the running of single tests using tox possible --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 562da2dc..23267390 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ deps = sql12: sqlalchemy>=1.2,<1.3 sql13: sqlalchemy>=1.3,<1.4 commands = - pytest graphene_sqlalchemy --cov=graphene_sqlalchemy {posargs} + pytest {posargs:graphene_sqlalchemy --cov=graphene_sqlalchemy} [testenv:pre-commit] basepython=python3.7 From e41531193bf3c6eafe314b1cef497eab998fd7ea Mon Sep 17 00:00:00 2001 From: Jonathan Ehwald Date: Tue, 5 Jan 2021 18:42:02 +0100 Subject: [PATCH 04/19] Resolve shadowing of the type keyword The same has been done in graphene. --- graphene_sqlalchemy/converter.py | 7 ++++--- graphene_sqlalchemy/fields.py | 18 +++++++++--------- graphene_sqlalchemy/tests/test_types.py | 4 ++-- graphene_sqlalchemy/types.py | 8 ++++---- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index f4b805e2..b5629770 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -110,9 +110,9 @@ def _convert_o2m_or_m2m_relationship(relationship_prop, obj_type, batching, conn def convert_sqlalchemy_hybrid_method(hybrid_prop, resolver, **field_kwargs): - if 'type' not in field_kwargs: + if 'type_' not in field_kwargs: # TODO The default type should be dependent on the type of the property propety. - field_kwargs['type'] = String + field_kwargs['type_'] = String return Field( resolver=resolver, @@ -156,7 +156,8 @@ def inner(fn): def convert_sqlalchemy_column(column_prop, registry, resolver, **field_kwargs): column = column_prop.columns[0] - field_kwargs.setdefault('type', convert_sqlalchemy_type(getattr(column, "type", None), column, registry)) + + field_kwargs.setdefault('type_', convert_sqlalchemy_type(getattr(column, "type", None), column, registry)) field_kwargs.setdefault('required', not is_column_nullable(column)) field_kwargs.setdefault('description', get_column_doc(column)) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index 780fcbf0..2fad07ef 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -19,10 +19,10 @@ class UnsortedSQLAlchemyConnectionField(ConnectionField): def type(self): from .types import SQLAlchemyObjectType - _type = super(ConnectionField, self).type - nullable_type = get_nullable_type(_type) + type_ = super(ConnectionField, self).type + nullable_type = get_nullable_type(type_) if issubclass(nullable_type, Connection): - return _type + return type_ assert issubclass(nullable_type, SQLAlchemyObjectType), ( "SQLALchemyConnectionField only accepts SQLAlchemyObjectType types, not {}" ).format(nullable_type.__name__) @@ -31,7 +31,7 @@ def type(self): ), "The type {} doesn't have a connection".format( nullable_type.__name__ ) - assert _type == nullable_type, ( + assert type_ == nullable_type, ( "Passing a SQLAlchemyObjectType instance is deprecated. " "Pass the connection type instead accessible via SQLAlchemyObjectType.connection" ) @@ -88,8 +88,8 @@ def get_resolver(self, parent_resolver): # TODO Rename this to SortableSQLAlchemyConnectionField class SQLAlchemyConnectionField(UnsortedSQLAlchemyConnectionField): - def __init__(self, type, *args, **kwargs): - nullable_type = get_nullable_type(type) + def __init__(self, type_, *args, **kwargs): + nullable_type = get_nullable_type(type_) if "sort" not in kwargs and issubclass(nullable_type, Connection): # Let super class raise if type is not a Connection try: @@ -103,7 +103,7 @@ def __init__(self, type, *args, **kwargs): ) elif "sort" in kwargs and kwargs["sort"] is None: del kwargs["sort"] - super(SQLAlchemyConnectionField, self).__init__(type, *args, **kwargs) + super(SQLAlchemyConnectionField, self).__init__(type_, *args, **kwargs) @classmethod def get_query(cls, model, info, sort=None, **args): @@ -148,13 +148,13 @@ def default_connection_field_factory(relationship, registry, **field_kwargs): __connectionFactory = UnsortedSQLAlchemyConnectionField -def createConnectionField(_type, **field_kwargs): +def createConnectionField(type_, **field_kwargs): warnings.warn( 'createConnectionField is deprecated and will be removed in the next ' 'major version. Use SQLAlchemyObjectType.Meta.connection_field_factory instead.', DeprecationWarning, ) - return __connectionFactory(_type, **field_kwargs) + return __connectionFactory(type_, **field_kwargs) def registerConnectionFieldFactory(factoryMethod): diff --git a/graphene_sqlalchemy/tests/test_types.py b/graphene_sqlalchemy/tests/test_types.py index bf563b6e..eeaafe3b 100644 --- a/graphene_sqlalchemy/tests/test_types.py +++ b/graphene_sqlalchemy/tests/test_types.py @@ -136,10 +136,10 @@ class Meta: # columns email = ORMField(deprecation_reason='Overridden') - email_v2 = ORMField(model_attr='email', type=Int) + email_v2 = ORMField(model_attr='email', type_=Int) # column_property - column_prop = ORMField(type=String) + column_prop = ORMField(type_=String) # composite composite_prop = ORMField() diff --git a/graphene_sqlalchemy/types.py b/graphene_sqlalchemy/types.py index ff22cded..72f06c06 100644 --- a/graphene_sqlalchemy/types.py +++ b/graphene_sqlalchemy/types.py @@ -27,7 +27,7 @@ class ORMField(OrderedType): def __init__( self, model_attr=None, - type=None, + type_=None, required=None, description=None, deprecation_reason=None, @@ -49,7 +49,7 @@ class MyType(SQLAlchemyObjectType): class Meta: model = MyModel - id = ORMField(type=graphene.Int) + id = ORMField(type_=graphene.Int) name = ORMField(required=True) -> MyType.id will be of type Int (vs ID). @@ -58,7 +58,7 @@ class Meta: :param str model_attr: Name of the SQLAlchemy model attribute used to resolve this field. Default to the name of the attribute referencing the ORMField. - :param type: + :param type_: Default to the type mapping in converter.py. :param str description: Default to the `doc` attribute of the SQLAlchemy column property. @@ -77,7 +77,7 @@ class Meta: # The is only useful for documentation and auto-completion common_kwargs = { 'model_attr': model_attr, - 'type': type, + 'type_': type_, 'required': required, 'description': description, 'deprecation_reason': deprecation_reason, From 229e13a09f7119a064a3a915fca18c520668c302 Mon Sep 17 00:00:00 2001 From: Jonathan Ehwald Date: Tue, 5 Jan 2021 18:47:41 +0100 Subject: [PATCH 05/19] Port enum related tests --- graphene_sqlalchemy/tests/test_query_enums.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphene_sqlalchemy/tests/test_query_enums.py b/graphene_sqlalchemy/tests/test_query_enums.py index ec585d57..5166c45f 100644 --- a/graphene_sqlalchemy/tests/test_query_enums.py +++ b/graphene_sqlalchemy/tests/test_query_enums.py @@ -32,7 +32,7 @@ def resolve_reporters(self, _info): def resolve_pets(self, _info, kind): query = session.query(Pet) if kind: - query = query.filter_by(pet_kind=kind) + query = query.filter_by(pet_kind=kind.value) return query query = """ @@ -131,7 +131,7 @@ class Query(graphene.ObjectType): def resolve_pet(self, info, kind=None): query = session.query(Pet) if kind: - query = query.filter(Pet.pet_kind == kind) + query = query.filter(Pet.pet_kind == kind.value) return query.first() query = """ From 744e9a965bd801514779c4e87ace6b2d6e9c064c Mon Sep 17 00:00:00 2001 From: Jonathan Ehwald Date: Tue, 5 Jan 2021 18:48:55 +0100 Subject: [PATCH 06/19] Port relay connection fields --- graphene_sqlalchemy/fields.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index 2fad07ef..cb0fccf9 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -7,8 +7,8 @@ from graphene import NonNull from graphene.relay import Connection, ConnectionField -from graphene.relay.connection import PageInfo -from graphql_relay.connection.arrayconnection import connection_from_list_slice +from graphene.relay.connection import PageInfo, connection_adapter, page_info_adapter +from graphql_relay.connection.arrayconnection import connection_from_array_slice from .batching import get_batch_resolver from .utils import get_query @@ -53,15 +53,19 @@ def resolve_connection(cls, connection_type, model, info, args, resolved): _len = resolved.count() else: _len = len(resolved) - connection = connection_from_list_slice( - resolved, - args, + + def adjusted_connection_adapter(edges, pageInfo): + return connection_adapter(connection_type, edges, pageInfo) + + connection = connection_from_array_slice( + array_slice=resolved, + args=args, slice_start=0, - list_length=_len, - list_slice_length=_len, - connection_type=connection_type, - pageinfo_type=PageInfo, + array_length=_len, + array_slice_length=_len, + connection_type=adjusted_connection_adapter, edge_type=connection_type.Edge, + page_info_type=page_info_adapter, ) connection.iterable = resolved connection.length = _len @@ -77,7 +81,7 @@ def connection_resolver(cls, resolver, connection_type, model, root, info, **arg return on_resolve(resolved) - def get_resolver(self, parent_resolver): + def wrap_resolve(self, parent_resolver): return partial( self.connection_resolver, parent_resolver, @@ -123,7 +127,7 @@ class BatchSQLAlchemyConnectionField(UnsortedSQLAlchemyConnectionField): Use at your own risk. """ - def get_resolver(self, parent_resolver): + def wrap_resolve(self, parent_resolver): return partial( self.connection_resolver, self.resolver, From 6a5fdcb0c1a4839194e7140f1282ebb1f59b7a56 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Sun, 2 May 2021 10:22:23 +0200 Subject: [PATCH 07/19] Remove dependency on external mock package. Python 3 bundles mock in stdlib. --- graphene_sqlalchemy/tests/test_types.py | 3 ++- setup.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/graphene_sqlalchemy/tests/test_types.py b/graphene_sqlalchemy/tests/test_types.py index eeaafe3b..ffa0333d 100644 --- a/graphene_sqlalchemy/tests/test_types.py +++ b/graphene_sqlalchemy/tests/test_types.py @@ -1,4 +1,5 @@ -import mock +from unittest import mock + import pytest import six # noqa F401 diff --git a/setup.py b/setup.py index 924b5e3b..5bece81f 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,6 @@ tests_require = [ "pytest==4.3.1", - "mock==2.0.0", "pytest-cov==2.6.1", "sqlalchemy_utils==0.33.9", "pytest-benchmark==3.2.1", From 90618abbca2598e9835003b6b24b1376420f7550 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Sun, 2 May 2021 10:52:49 +0200 Subject: [PATCH 08/19] Pin SQLAlchemy below 1.4 until we figure out what needs upgrading. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5bece81f..6155f41a 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ "graphene>=3.0b5", "promise>=2.3", # Tests fail with 1.0.19 - "SQLAlchemy>=1.2,<2", + "SQLAlchemy>=1.2,<1.4", "six>=1.10.0,<2", "singledispatch>=3.4.0.3,<4", ] From 96dd48efeff501bb620395701f2db5b5087f7a8d Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Sun, 2 May 2021 11:50:54 +0200 Subject: [PATCH 09/19] Ignore mypy cache. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a97b8c21..c4a735fe 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,6 @@ target/ # Databases *.sqlite3 .vscode + +# mypy cache +.mypy_cache/ From 91fd3bfc498132d3676f041c7233bbed35177fe9 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Mon, 3 May 2021 20:00:05 +0200 Subject: [PATCH 10/19] Use sqlalchemy_utils which supports SQLAlchemy 1.4 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 6155f41a..7122dde6 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ "graphene>=3.0b5", "promise>=2.3", # Tests fail with 1.0.19 - "SQLAlchemy>=1.2,<1.4", + "SQLAlchemy>=1.2,<2.0", "six>=1.10.0,<2", "singledispatch>=3.4.0.3,<4", ] @@ -28,7 +28,7 @@ tests_require = [ "pytest==4.3.1", "pytest-cov==2.6.1", - "sqlalchemy_utils==0.33.9", + "sqlalchemy_utils==0.37.0", "pytest-benchmark==3.2.1", ] From 4a7271fadb149857430453d087cbfdf2b2d5c180 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Mon, 3 May 2021 20:03:26 +0200 Subject: [PATCH 11/19] Upgrade test dependencies. Allow for some flexibility on version numbers. --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 7122dde6..596e6b08 100644 --- a/setup.py +++ b/setup.py @@ -26,10 +26,10 @@ requirements.append("enum34 >= 1.1.6") tests_require = [ - "pytest==4.3.1", - "pytest-cov==2.6.1", - "sqlalchemy_utils==0.37.0", - "pytest-benchmark==3.2.1", + "pytest>=6.2.0,<7.0", + "pytest-cov>=2.11.0,<3.0", + "sqlalchemy_utils>=0.37.0,<1.0", + "pytest-benchmark>=3.4.0,<4.0", ] setup( From 9975286aed7f2fb966a18dd4a8267ee5bd123875 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 12:15:12 +0200 Subject: [PATCH 12/19] Use built-in singledispatch. --- graphene_sqlalchemy/converter.py | 2 +- setup.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index b5629770..f782e5d0 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -1,6 +1,6 @@ from enum import EnumMeta +from functools import singledispatch -from singledispatch import singledispatch from sqlalchemy import types from sqlalchemy.dialects import postgresql from sqlalchemy.orm import interfaces, strategies diff --git a/setup.py b/setup.py index 596e6b08..3df49e0a 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,6 @@ # Tests fail with 1.0.19 "SQLAlchemy>=1.2,<2.0", "six>=1.10.0,<2", - "singledispatch>=3.4.0.3,<4", ] try: import enum From 113ac255731b881830f52107495ea7bba82e6eb0 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 12:16:00 +0200 Subject: [PATCH 13/19] Remove dependency on six. --- graphene_sqlalchemy/enums.py | 3 +-- graphene_sqlalchemy/fields.py | 5 ++--- graphene_sqlalchemy/registry.py | 3 +-- graphene_sqlalchemy/tests/test_types.py | 1 - setup.py | 1 - 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/graphene_sqlalchemy/enums.py b/graphene_sqlalchemy/enums.py index 0adea107..f100be19 100644 --- a/graphene_sqlalchemy/enums.py +++ b/graphene_sqlalchemy/enums.py @@ -1,4 +1,3 @@ -import six from sqlalchemy.orm import ColumnProperty from sqlalchemy.types import Enum as SQLAlchemyEnumType @@ -63,7 +62,7 @@ def enum_for_field(obj_type, field_name): if not isinstance(obj_type, type) or not issubclass(obj_type, SQLAlchemyObjectType): raise TypeError( "Expected SQLAlchemyObjectType, but got: {!r}".format(obj_type)) - if not field_name or not isinstance(field_name, six.string_types): + if not field_name or not isinstance(field_name, str): raise TypeError( "Expected a field name, but got: {!r}".format(field_name)) registry = obj_type._meta.registry diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index cb0fccf9..abfe0c52 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -1,7 +1,6 @@ import warnings from functools import partial -import six from promise import Promise, is_thenable from sqlalchemy.orm.query import Query @@ -56,7 +55,7 @@ def resolve_connection(cls, connection_type, model, info, args, resolved): def adjusted_connection_adapter(edges, pageInfo): return connection_adapter(connection_type, edges, pageInfo) - + connection = connection_from_array_slice( array_slice=resolved, args=args, @@ -113,7 +112,7 @@ def __init__(self, type_, *args, **kwargs): def get_query(cls, model, info, sort=None, **args): query = get_query(model, info.context) if sort is not None: - if isinstance(sort, six.string_types): + if isinstance(sort, str): query = query.order_by(sort.value) else: query = query.order_by(*(col.value for col in sort)) diff --git a/graphene_sqlalchemy/registry.py b/graphene_sqlalchemy/registry.py index c20bc2ca..acfa744b 100644 --- a/graphene_sqlalchemy/registry.py +++ b/graphene_sqlalchemy/registry.py @@ -1,6 +1,5 @@ from collections import defaultdict -import six from sqlalchemy.types import Enum as SQLAlchemyEnumType from graphene import Enum @@ -43,7 +42,7 @@ def register_orm_field(self, obj_type, field_name, orm_field): raise TypeError( "Expected SQLAlchemyObjectType, but got: {!r}".format(obj_type) ) - if not field_name or not isinstance(field_name, six.string_types): + if not field_name or not isinstance(field_name, str): raise TypeError("Expected a field name, but got: {!r}".format(field_name)) self._registry_orm_fields[obj_type][field_name] = orm_field diff --git a/graphene_sqlalchemy/tests/test_types.py b/graphene_sqlalchemy/tests/test_types.py index ffa0333d..32f01509 100644 --- a/graphene_sqlalchemy/tests/test_types.py +++ b/graphene_sqlalchemy/tests/test_types.py @@ -1,7 +1,6 @@ from unittest import mock import pytest -import six # noqa F401 from graphene import (Dynamic, Field, GlobalID, Int, List, Node, NonNull, ObjectType, Schema, String) diff --git a/setup.py b/setup.py index 3df49e0a..f220ae61 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ "promise>=2.3", # Tests fail with 1.0.19 "SQLAlchemy>=1.2,<2.0", - "six>=1.10.0,<2", ] try: import enum From a0cb208f2ba1395d29e494acc0ab979a6b665bc2 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 12:16:32 +0200 Subject: [PATCH 14/19] Assume enum is always available. As we're targeting Python >= 3.6, this module should always be in stdlib. --- setup.cfg | 2 +- setup.py | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 4e8e5029..4e554938 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,7 @@ max-line-length = 120 no_lines_before=FIRSTPARTY known_graphene=graphene,graphql_relay,flask_graphql,graphql_server,sphinx_graphene_theme known_first_party=graphene_sqlalchemy -known_third_party=app,database,flask,graphql,mock,models,nameko,pkg_resources,promise,pytest,schema,setuptools,singledispatch,six,sqlalchemy,sqlalchemy_utils +known_third_party=app,database,flask,graphql,models,nameko,pkg_resources,promise,pytest,schema,setuptools,sqlalchemy,sqlalchemy_utils sections=FUTURE,STDLIB,THIRDPARTY,GRAPHENE,FIRSTPARTY,LOCALFOLDER skip_glob=examples/nameko_sqlalchemy diff --git a/setup.py b/setup.py index f220ae61..162519a7 100644 --- a/setup.py +++ b/setup.py @@ -18,10 +18,6 @@ # Tests fail with 1.0.19 "SQLAlchemy>=1.2,<2.0", ] -try: - import enum -except ImportError: # Python < 2.7 and Python 3.3 - requirements.append("enum34 >= 1.1.6") tests_require = [ "pytest>=6.2.0,<7.0", From 2926c7cffa424b770b5925eaa596588540210742 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 12:31:30 +0200 Subject: [PATCH 15/19] Add more tox factors for Python 3.8 and SQLAlchemy 1.4 --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 23267390..44f52f7c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = pre-commit,py{27,35,36,37}-sql{11,12,13} +envlist = pre-commit,py{36,37,38}-sql{11,12,13,14} skipsdist = true minversion = 3.7.0 @@ -9,6 +9,7 @@ deps = sql11: sqlalchemy>=1.1,<1.2 sql12: sqlalchemy>=1.2,<1.3 sql13: sqlalchemy>=1.3,<1.4 + sql14: sqlalchemy>=1.4,<1.5 commands = pytest {posargs:graphene_sqlalchemy --cov=graphene_sqlalchemy} From 6521aa627b7e930400221c4ea75eec03b4e96172 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 12:36:53 +0200 Subject: [PATCH 16/19] Use non-deprecated fixture decorator for session_factory. --- graphene_sqlalchemy/tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_sqlalchemy/tests/conftest.py b/graphene_sqlalchemy/tests/conftest.py index 98515051..34ba9d8a 100644 --- a/graphene_sqlalchemy/tests/conftest.py +++ b/graphene_sqlalchemy/tests/conftest.py @@ -22,7 +22,7 @@ def convert_composite_class(composite, registry): return graphene.Field(graphene.Int) -@pytest.yield_fixture(scope="function") +@pytest.fixture(scope="function") def session_factory(): engine = create_engine(test_db_url) Base.metadata.create_all(engine) From 54a30520e43e671c5f37c8c27f8f33a390eb7dcc Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 15:06:53 +0200 Subject: [PATCH 17/19] Ensure consistent handling of graphene Enums, enum values and plain strings. --- graphene_sqlalchemy/fields.py | 26 ++++++++++++++------ graphene_sqlalchemy/tests/test_benchmark.py | 1 + graphene_sqlalchemy/tests/test_sort_enums.py | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/graphene_sqlalchemy/fields.py b/graphene_sqlalchemy/fields.py index abfe0c52..f756277a 100644 --- a/graphene_sqlalchemy/fields.py +++ b/graphene_sqlalchemy/fields.py @@ -1,3 +1,4 @@ +import enum import warnings from functools import partial @@ -6,11 +7,13 @@ from graphene import NonNull from graphene.relay import Connection, ConnectionField -from graphene.relay.connection import PageInfo, connection_adapter, page_info_adapter -from graphql_relay.connection.arrayconnection import connection_from_array_slice +from graphene.relay.connection import (PageInfo, connection_adapter, + page_info_adapter) +from graphql_relay.connection.arrayconnection import \ + connection_from_array_slice from .batching import get_batch_resolver -from .utils import get_query +from .utils import EnumValue, get_query class UnsortedSQLAlchemyConnectionField(ConnectionField): @@ -112,10 +115,19 @@ def __init__(self, type_, *args, **kwargs): def get_query(cls, model, info, sort=None, **args): query = get_query(model, info.context) if sort is not None: - if isinstance(sort, str): - query = query.order_by(sort.value) - else: - query = query.order_by(*(col.value for col in sort)) + if not isinstance(sort, list): + sort = [sort] + sort_args = [] + # ensure consistent handling of graphene Enums, enum values and + # plain strings + for item in sort: + if isinstance(item, enum.Enum): + sort_args.append(item.value.value) + elif isinstance(item, EnumValue): + sort_args.append(item.value) + else: + sort_args.append(item) + query = query.order_by(*sort_args) return query diff --git a/graphene_sqlalchemy/tests/test_benchmark.py b/graphene_sqlalchemy/tests/test_benchmark.py index 8d8a111f..d2d78592 100644 --- a/graphene_sqlalchemy/tests/test_benchmark.py +++ b/graphene_sqlalchemy/tests/test_benchmark.py @@ -1,4 +1,5 @@ import pytest + import graphene from graphene import relay diff --git a/graphene_sqlalchemy/tests/test_sort_enums.py b/graphene_sqlalchemy/tests/test_sort_enums.py index d6f6965d..6291d4f8 100644 --- a/graphene_sqlalchemy/tests/test_sort_enums.py +++ b/graphene_sqlalchemy/tests/test_sort_enums.py @@ -354,7 +354,7 @@ def makeNodes(nodeList): """ result = schema.execute(queryError, context_value={"session": session}) assert result.errors is not None - assert '"sort" has invalid value' in result.errors[0].message + assert 'cannot represent non-enum value' in result.errors[0].message queryNoSort = """ query sortTest { From e75c94e3be4ae3603aa097411574a5c6f3106b10 Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 15:17:00 +0200 Subject: [PATCH 18/19] Disable converter test for Binary type. SQLAlchemy 1.4+ does not export Binary directly. We should decide whether to keep this test, update for another unknown type, or remove it altogether. --- graphene_sqlalchemy/tests/test_converter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index f0fc1802..5f362d5d 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -47,7 +47,8 @@ class Model(declarative_base()): return convert_sqlalchemy_column(column_prop, get_global_registry(), mock_resolver) -def test_should_unknown_sqlalchemy_field_raise_exception(): +def _test_should_unknown_sqlalchemy_field_raise_exception(): + # TODO: SQLALchemy does not export types.Binary, remove or update this test re_err = "Don't know how to convert the SQLAlchemy field" with pytest.raises(Exception, match=re_err): # support legacy Binary type and subsequent LargeBinary From b3cc28416fa7167cf372c041df62def2418e0b2d Mon Sep 17 00:00:00 2001 From: Zbigniew Siciarz Date: Tue, 4 May 2021 15:34:18 +0200 Subject: [PATCH 19/19] Keep consistent versions between travis.yml and setup.py --- .travis.yml | 14 ++++++++------ setup.py | 6 ++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a988428..18ef6ca8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,6 @@ language: python matrix: include: - # Python 2.7 - - env: TOXENV=py27 - python: 2.7 - # Python 3.5 - - env: TOXENV=py35 - python: 3.5 # Python 3.6 - env: TOXENV=py36 python: 3.6 @@ -14,6 +8,10 @@ matrix: - env: TOXENV=py37 python: 3.7 dist: xenial + # Python 3.8 + - env: TOXENV=py38 + python: 3.8 + dist: xenial # SQLAlchemy 1.1 - env: TOXENV=py37-sql11 python: 3.7 @@ -26,6 +24,10 @@ matrix: - env: TOXENV=py37-sql13 python: 3.7 dist: xenial + # SQLAlchemy 1.4 + - env: TOXENV=py37-sql14 + python: 3.7 + dist: xenial # Pre-commit - env: TOXENV=pre-commit python: 3.7 diff --git a/setup.py b/setup.py index 162519a7..4394985e 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ "graphene>=3.0b5", "promise>=2.3", # Tests fail with 1.0.19 - "SQLAlchemy>=1.2,<2.0", + "SQLAlchemy>=1.1,<2.0", ] tests_require = [ @@ -39,12 +39,10 @@ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Topic :: Software Development :: Libraries", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", "Programming Language :: Python :: Implementation :: PyPy", ], keywords="api graphql protocol rest relay graphene",