graphql-python / graphene-sqlalchemy

Graphene SQLAlchemy integration
http://docs.graphene-python.org/projects/sqlalchemy/en/latest/
MIT License
980 stars 226 forks source link

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

Closed lame closed 2 years ago

lame commented 4 years ago

Due to the following lines:

https://github.com/graphql-python/graphene-sqlalchemy/blob/421f8e48d169a91e20328108c6f56ae0987d21b8/graphene_sqlalchemy/converter.py#L19-L22

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'>]
erikwrede commented 2 years ago

Should be fixed in 3.0.0b2

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.