ydb-platform / ydb-sqlalchemy

YQL Dialect for SQLAlchemy
Apache License 2.0
18 stars 5 forks source link

Fix false cache hit #43

Closed LuckySting closed 2 months ago

LuckySting commented 2 months ago

Problem

The ydb.DataQuery is cached within a session scope using a hash of sql text as key. This lead to issues if a query is executed with different types (optional/required). For example, this code snipped reproduces the error:

with connection_no_trans.begin() as transaction:
    connection_no_trans.execute(sa.insert(table).values([{"id": 1, "text": "foo"}]))
    connection_no_trans.execute(sa.insert(table).values([{"id": 2, "text": None}]))

The "text" parameter in the first execution has type Utf8 and Optional<Utf8> in the second, which leads to error.

Proposal

There is an ability to construct a cache key manually on the caller side, so it is possible to include types of parameters to it.

Result

The example query is executed without an error.