PostgreSQL specific fields (DATERANGE, TSTZRANGE, etc.) break when SQLAlchemy-Utils is installed · Issue #269 · graphql-python/graphene-sqlalchemy (original) (raw)
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=, 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'>]