asyncpgsa icon indicating copy to clipboard operation
asyncpgsa copied to clipboard

compile_query fails with sqlalchemy 1.4

Open trvrmcs opened this issue 3 years ago • 5 comments

This works fine with asyncpgsa version 0.27.1 and sqlalchemy: 1.3.23, but fails when I upgrade to sqlalchemy 1.4.4.

import asyncpgsa
import sqlalchemy as sa

Thing = sa.Table("thing", sa.MetaData(), sa.Column("name", sa.Text))
query = Thing.insert().values(name="name").returning(Thing)
asyncpgsa.compile_query(query)

This prevents me from running any code that uses an INSERT statement.

The error seems to be here:

https://github.com/CanopyTax/asyncpgsa/blob/master/asyncpgsa/connection.py#L36

    if isinstance(query.parameters, list):

because sqlalchemy.sql.dml.Insert no longer has a parameters attribute.

For now I'm dealing with this by pinning to an earlier sqlalchemy version. It's not clear to me what the fix should be, because the sqlalchemy internals seem to have changed considerably between versions.

trvrmcs avatar Apr 01 '21 19:04 trvrmcs

For some new projects maybe a good choice to use async support of sqlalchemy

asyncio extension in sqlalchemy

I am thinking about this transition. I think it would be good to have some benchmarks for this..

dyens avatar Apr 06 '21 18:04 dyens

I am actually thinking of deprecating this library now that sqlalchemy supports asyncpg directly. I already migrated an application too it, and might provide a migration guide.

nhumrich avatar Apr 13 '21 01:04 nhumrich

A migration guide would be helpful - I've built a number of projects on top of asyncpg over the years. Thank you for all your work in creating it, maintaining it, and being so responsive to my questions. (You helped me with a JSON encoding issue at PyCon a few years ago, if I recall correctly.)

trvrmcs avatar Apr 13 '21 13:04 trvrmcs

Just for the record. Native async support SQLAlchemy has some problems. And the most of them probably will never be fixed. The most notable is the lack of auto-commit mode, and wrapping each select into async with db.begin(): is really annoying. Also it has issues with pgbouncer.

ods avatar Sep 19 '22 15:09 ods

+1 for the migration guide.

nagyt2 avatar Aug 21 '23 14:08 nagyt2