Skip to content
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

Using try_cast in SQLAlchemy #473

Closed
1 task done
dwolfeu opened this issue Jul 18, 2024 · 1 comment · Fixed by #474
Closed
1 task done

Using try_cast in SQLAlchemy #473

dwolfeu opened this issue Jul 18, 2024 · 1 comment · Fixed by #474

Comments

@dwolfeu
Copy link
Member

dwolfeu commented Jul 18, 2024

Expected behavior

sqlalchemy.sql.try_cast should work.

Actual behavior

It doesn't work.

Steps To Reproduce

from sqlalchemy import create_engine, Column, Integer, String, select, try_cast
from sqlalchemy.orm import declarative_base, Session
from trino.auth import OAuth2Authentication

engine = create_engine(
'<url-of-trino-server>',
    connect_args={
        'auth': OAuth2Authentication(),
        'http_scheme': 'https',
        'catalog': '<catalog-name>'
    }
)

Base = declarative_base()

class MyTable(Base):
    __tablename__ = 'foobar'
    __table_args__ = {'schema': 'baz'}
    id = Column(Integer, primary_key=True)

session = Session(engine)
stmt = select(try_cast(MyTable.id,String)).where(MyTable.id.in_([1,2,3]))

for i in session.scalars(stmt):
    print(i)

Log output

AttributeError: 'TrinoSQLCompiler' object has no attribute 'visit_try_cast'

The above exception was the direct cause of the following exception:

# <Lots of detailed error messages>

UnsupportedCompilationError: Compiler <trino.sqlalchemy.compiler.TrinoSQLCompiler object at 0x1696e8d60> can't render element of type <class 'sqlalchemy.sql.elements.TryCast'> (Background on this error at: https://sqlalche.me/e/20/l7de)

Operating System

macOS Sonoma 14.5

Trino Python client version

0.329.0

Trino Server version

426

Python version

3.10.2

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant