22import sys
33from typing import Dict , Tuple , Union
44
5+ import graphene
56import pytest
67import sqlalchemy
78import sqlalchemy_utils as sqa_utils
8- from sqlalchemy import Column , func , select , types
9+ from graphene .relay import Node
10+ from graphene .types .structures import Structure
11+ from sqlalchemy import Column , func , types
912from sqlalchemy .dialects import postgresql
1013from sqlalchemy .ext .declarative import declarative_base
1114from sqlalchemy .ext .hybrid import hybrid_property
1215from sqlalchemy .inspection import inspect
1316from sqlalchemy .orm import column_property , composite
1417
15- import graphene
16- from graphene .relay import Node
17- from graphene .types .structures import Structure
18-
18+ from .models import (
19+ Article ,
20+ CompositeFullName ,
21+ Pet ,
22+ Reporter ,
23+ ShoppingCart ,
24+ ShoppingCartItem ,
25+ )
26+ from .utils import wrap_select_func
1927from ..converter import (
2028 convert_sqlalchemy_column ,
2129 convert_sqlalchemy_composite ,
2735from ..fields import UnsortedSQLAlchemyConnectionField , default_connection_field_factory
2836from ..registry import Registry , get_global_registry
2937from ..types import ORMField , SQLAlchemyObjectType
38+ from ..utils import is_sqlalchemy_version_less_than
3039from .models import (
3140 Article ,
3241 CompositeFullName ,
@@ -204,9 +213,9 @@ def prop_method() -> int | str:
204213 return "not allowed in gql schema"
205214
206215 with pytest .raises (
207- ValueError ,
208- match = r"Cannot convert hybrid_property Union to "
209- r"graphene.Union: the Union contains scalars. \.*" ,
216+ ValueError ,
217+ match = r"Cannot convert hybrid_property Union to "
218+ r"graphene.Union: the Union contains scalars. \.*" ,
210219 ):
211220 get_hybrid_property_type (prop_method )
212221
@@ -460,7 +469,7 @@ class TestEnum(enum.IntEnum):
460469
461470def test_should_columproperty_convert ():
462471 field = get_field_from_column (
463- column_property (select ([ func .sum (func .cast (id , types .Integer ))] ).where (id == 1 ))
472+ column_property (wrap_select_func ( func .sum (func .cast (id , types .Integer ))).where (id == 1 ))
464473 )
465474
466475 assert field .type == graphene .Int
@@ -477,10 +486,18 @@ def test_should_jsontype_convert_jsonstring():
477486 assert get_field (types .JSON ).type == graphene .JSONString
478487
479488
489+ @pytest .mark .skipif (
490+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
491+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
492+ )
480493def test_should_variant_int_convert_int ():
481494 assert get_field (types .Variant (types .Integer (), {})).type == graphene .Int
482495
483496
497+ @pytest .mark .skipif (
498+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
499+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
500+ )
484501def test_should_variant_string_convert_string ():
485502 assert get_field (types .Variant (types .String (), {})).type == graphene .String
486503
@@ -811,8 +828,8 @@ class Meta:
811828 )
812829
813830 for (
814- hybrid_prop_name ,
815- hybrid_prop_expected_return_type ,
831+ hybrid_prop_name ,
832+ hybrid_prop_expected_return_type ,
816833 ) in shopping_cart_item_expected_types .items ():
817834 hybrid_prop_field = ShoppingCartItemType ._meta .fields [hybrid_prop_name ]
818835
@@ -823,7 +840,7 @@ class Meta:
823840 str (hybrid_prop_expected_return_type ),
824841 )
825842 assert (
826- hybrid_prop_field .description is None
843+ hybrid_prop_field .description is None
827844 ) # "doc" is ignored by hybrid property
828845
829846 ###################################################
@@ -870,8 +887,8 @@ class Meta:
870887 )
871888
872889 for (
873- hybrid_prop_name ,
874- hybrid_prop_expected_return_type ,
890+ hybrid_prop_name ,
891+ hybrid_prop_expected_return_type ,
875892 ) in shopping_cart_expected_types .items ():
876893 hybrid_prop_field = ShoppingCartType ._meta .fields [hybrid_prop_name ]
877894
@@ -882,5 +899,5 @@ class Meta:
882899 str (hybrid_prop_expected_return_type ),
883900 )
884901 assert (
885- hybrid_prop_field .description is None
902+ hybrid_prop_field .description is None
886903 ) # "doc" is ignored by hybrid property
0 commit comments