Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lame opened this issue Feb 27, 2020 · 2 comments
Labels

Comments

@lame
Copy link

lame commented Feb 27, 2020

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'>]
@lame lame changed the title PostgreSQL specific fields (DATERANGE, TSTZRANGE, etc.) break when SQLAlchemy-Utils is installed in python environment PostgreSQL specific fields (DATERANGE, TSTZRANGE, etc.) break when SQLAlchemy-Utils is installed Feb 27, 2020
@erikwrede erikwrede added the bug label Apr 28, 2022
@erikwrede
Copy link
Member

Should be fixed in 3.0.0b2

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants