Skip to content

PostgreSQL specific fields (DATERANGE, TSTZRANGE, etc.) break when SQLAlchemy-Utils is installed #269

Closed
@lame

Description

@lame

Due to the following lines:

try:
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType, TSVectorType
except ImportError:
ChoiceType = JSONType = ScalarListType = TSVectorType = object

Graphene will break with the following message when SQLAlchemy-Utils is installed:

Exception: Don't know how to convert the SQLAlchemy field Foo.bar (<class 'sqlalchemy.sql.schema.Column'>)

where Foo.bar is a TSTZRANGE type as follows:

In [11]: from script import base_script 
    ...: from sqlalchemy.inspection import inspect as sqlalchemyinspect 
    ...: from graphene_sqlalchemy.converter import convert_sqlalchemy_type 
    ...: from singledispatch import _compose_mro 
    ...: from foo import Foo
    ...:  
    ...: inspected_model = sqlalchemyinspect(Foo) 
    ...: print(inspected_model.columns.items()[5]) 
    ...: name, column = inspected_model.columns.items()[5] 
    ...: model_hierarchy = _compose_mro( 
    ...:     column.type.__class__, convert_sqlalchemy_type.registry.keys() 
    ...: ) 
    ...: reg = convert_sqlalchemy_type.registry
    ...: for model in model_hierarchy:
    ...:     if model in reg: 
    ...:         print(model, reg[model]) 
    ...:  
    ...: print(model_hierarchy) 
    ...:                                                                                                                                         
('bar', Column('bar', TSTZRANGE(), table=<foos>, nullable=False))
<class 'object'> <function convert_sqlalchemy_type at 0x108f88560>
[<class 'sqlalchemy.dialects.postgresql.ranges.TSTZRANGE'>, <class 'sqlalchemy.dialects.postgresql.ranges.RangeOperators'>, <class 'sqlalchemy.sql.type_api.TypeEngine'>, <class 'sqlalchemy.sql.visitors.Visitable'>, <class 'object'>]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions