-
Notifications
You must be signed in to change notification settings - Fork 258
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
SQLAlchemy 1.4 statements with .in_ operator not compiled correctly #577
Comments
I have the same problem again.
|
The simple solution would be as @flask-rabmq mentioned to add render_postcompile flag here and here I'm not sure how this is going to work with the cache. Maybe We should probably allow users to submit the desired value and have some sensible defaults. |
@paulefoe Look at this description. https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#change-4645. |
meet the same problem. my temp workaroud in user code:// try1: literal_binds query = db_devices.select().where(
db_devices.c.device_id.in_(device_id_list)
)
query = query.compile(compile_kwargs={"literal_binds": True}) # compile to final sql with args filled
query = str(query)
print('query:', type(query), query)
async with g.app.ctx.db.acquire() as conn:
return await (await conn.execute(query)).fetchall() // try2: render_postcompile + literal_execute // same effect query = db_devices.select().where(
# db_devices.c.device_id.in_(device_id_list)
db_devices.c.device_id.in_(
sa.bindparam('list', device_id_list, literal_execute=True) # effect on compile() with render_postcompile
)
)
query = query.compile(compile_kwargs={"render_postcompile": True}) # compile to final sql with args filled
query = str(query)
print('query:', type(query), query)
async with g.app.ctx.db.acquire() as conn:
return await (await conn.execute(query)).fetchall() @flask-rabmq 's fix in diff formatdiff with v0.0.22/aiomysql/sa/connection.py --- a/aiomysql/sa/connection.py
+++ b/aiomysql/sa/connection.py
@@ -148,13 +148,13 @@ class SAConnection:
key = query
compiled = self._compiled_cache.get(key)
if not compiled:
- compiled = query.compile(dialect=self._dialect)
+ compiled = query.compile(dialect=self._dialect, compile_kwargs={"render_postcompile": True})
if dp and dp.keys() == compiled.params.keys() \
or not (dp or compiled.params):
# we only want queries with bound params in cache
self._compiled_cache[key] = compiled
else:
- compiled = query.compile(dialect=self._dialect)
+ compiled = query.compile(dialect=self._dialect, compile_kwargs={"render_postcompile": True})
if not isinstance(query, DDLElement):
post_processed_params = self._base_params( worked well |
Same issue here. |
In SQLAlchemy version 1.4 they way statements using the
.in_
operator are compiled was changed to enable better caching. However this means statements need to be compiled with additional compile args in order to render correctly. You can read about the change here:https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#change-4645
The issue this manifests itself as:
The text was updated successfully, but these errors were encountered: