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_association_proxy ,
2129 convert_sqlalchemy_column ,
2836from ..fields import UnsortedSQLAlchemyConnectionField , default_connection_field_factory
2937from ..registry import Registry , get_global_registry
3038from ..types import ORMField , SQLAlchemyObjectType
39+ from ..utils import is_sqlalchemy_version_less_than
3140from .models import (
3241 Article ,
3342 CompositeFullName ,
@@ -206,9 +215,9 @@ def prop_method() -> int | str:
206215 return "not allowed in gql schema"
207216
208217 with pytest .raises (
209- ValueError ,
210- match = r"Cannot convert hybrid_property Union to "
211- r"graphene.Union: the Union contains scalars. \.*" ,
218+ ValueError ,
219+ match = r"Cannot convert hybrid_property Union to "
220+ r"graphene.Union: the Union contains scalars. \.*" ,
212221 ):
213222 get_hybrid_property_type (prop_method )
214223
@@ -462,7 +471,7 @@ class TestEnum(enum.IntEnum):
462471
463472def test_should_columproperty_convert ():
464473 field = get_field_from_column (
465- column_property (select ([ func .sum (func .cast (id , types .Integer ))] ).where (id == 1 ))
474+ column_property (wrap_select_func ( func .sum (func .cast (id , types .Integer ))).where (id == 1 ))
466475 )
467476
468477 assert field .type == graphene .Int
@@ -479,10 +488,18 @@ def test_should_jsontype_convert_jsonstring():
479488 assert get_field (types .JSON ).type == graphene .JSONString
480489
481490
491+ @pytest .mark .skipif (
492+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
493+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
494+ )
482495def test_should_variant_int_convert_int ():
483496 assert get_field (types .Variant (types .Integer (), {})).type == graphene .Int
484497
485498
499+ @pytest .mark .skipif (
500+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
501+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
502+ )
486503def test_should_variant_string_convert_string ():
487504 assert get_field (types .Variant (types .String (), {})).type == graphene .String
488505
@@ -871,8 +888,8 @@ class Meta:
871888 )
872889
873890 for (
874- hybrid_prop_name ,
875- hybrid_prop_expected_return_type ,
891+ hybrid_prop_name ,
892+ hybrid_prop_expected_return_type ,
876893 ) in shopping_cart_item_expected_types .items ():
877894 hybrid_prop_field = ShoppingCartItemType ._meta .fields [hybrid_prop_name ]
878895
@@ -883,7 +900,7 @@ class Meta:
883900 str (hybrid_prop_expected_return_type ),
884901 )
885902 assert (
886- hybrid_prop_field .description is None
903+ hybrid_prop_field .description is None
887904 ) # "doc" is ignored by hybrid property
888905
889906 ###################################################
@@ -930,8 +947,8 @@ class Meta:
930947 )
931948
932949 for (
933- hybrid_prop_name ,
934- hybrid_prop_expected_return_type ,
950+ hybrid_prop_name ,
951+ hybrid_prop_expected_return_type ,
935952 ) in shopping_cart_expected_types .items ():
936953 hybrid_prop_field = ShoppingCartType ._meta .fields [hybrid_prop_name ]
937954
@@ -942,5 +959,5 @@ class Meta:
942959 str (hybrid_prop_expected_return_type ),
943960 )
944961 assert (
945- hybrid_prop_field .description is None
962+ hybrid_prop_field .description is None
946963 ) # "doc" is ignored by hybrid property
0 commit comments