crate / sqlalchemy-cratedb

SQLAlchemy dialect for CrateDB.
https://cratedb.com/docs/sqlalchemy-cratedb/
Apache License 2.0
3 stars 2 forks source link

SQLAlchemy 2: Type support for patch to `visit_update` #84

Open amotl opened 1 year ago

amotl commented 1 year ago

Introduction

Within the CrateDB-specific statement compiler for SQLAlchemy, there is a patch to support CrateDB's container data types OBJECT and ARRAY. It is located at CrateCompilerSA20.visit_update().

About

SQLAlchemy 2 now wants to convert the crud_params list to a type-safe variant using sqlalchemy.cast().

# TODO: Complete SA20 migration.
# This is the column name/value joining code from SA20.
# It may be sensible to use this procedure instead of the old one.
text += ", ".join(
    expr + "=" + value
    for _, expr, value, _ in cast(
        "List[Tuple[Any, str, str, Any]]", crud_params
    )
)

That croaks with:

AttributeError: 'list' object has no attribute '_is_tuple_type'

Code

The relevant code region is this part within CrateCompilerSA20.visit_update:

https://github.com/crate/crate-python/blob/2ee91d52f6e07659c54337fe6bb08caf114e7469/src/crate/client/sqlalchemy/compat/core20.py#L116-L146

Discussion references