RazerM / sqlalchemy_aio

Asyncio strategy for SQLAlchemy.
Other
300 stars 17 forks source link

Not compatible with SQLAlchemy 1.4.2 #38

Closed vcalvert closed 2 years ago

vcalvert commented 3 years ago

This is the sort of error we see when attempting to use sqlalchemy_aio with trio and sqlalchemy==1.4.2:

File "/home/someuser/.local/lib/python3.8/site-packages/sqlalchemy_aio/strategy.py", line 1, in <module>
    from sqlalchemy.engine.strategies import DefaultEngineStrategy
ImportError: cannot import name 'DefaultEngineStrategy' from 'sqlalchemy.engine.strategies' (/home/someuser/.local/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py)
sycured commented 3 years ago

@vcalvert have you a good alternative?

vcalvert commented 3 years ago

@sycured, at this time, we don't have a tested alternative. At the moment, we've just pinned SQLAlchemy to <1.4.

We might use the built-in SQLAlchemy AsyncEngine via trio-asyncio, as that's relatively straightforward, but that's the only good option I'm aware of at the moment for use with trio. The AsyncEngine and other now-builtin parts provide a lot of the context managers, etc. so it may be a reasonable approach. Implementing a trio-compatible AsyncEngine would be more work, but wouldn't require the additional dependency (which we already need for some other things).

sycured commented 3 years ago

@vcalvert not really because I've an issue with metadata.reflect() which isn't working with new create_async_engine

Maybe I'll move to another orm or language because I can't manage the database by the orm.

It's why I looked at sqlalchemy-aio but ok, I'll downgrade sqlalchemy and try it. Thanks

prophile commented 3 years ago

Would you mind reflecting the <1.4 requirement in the install_requires of setup.py?

imperialguy commented 2 years ago

Are there any plans to upgrade this lib to work with the latest sqla version?

RazerM commented 2 years ago

There are no plans to support SQLAlchemy 1.4, which adds proper async support.

imperialguy commented 2 years ago

I think this is what you are referring to. But, I want to use it with trio.

imperialguy commented 2 years ago

Any ideas on how to use it with trio?

vcalvert commented 2 years ago

Per the various above comments, the restriction on SQLAlchemy version has been added as of release 0.17.0.

As I noted above, one way to use newer SQLAlchemy with trio is to use the SQLAlchemy-provided asyncio code with trio-asyncio.

It's not terribly difficult, but it does bring in more dependences...

The other option is to essentially use a worker thread, i.e.

result = await trio.to_thread.run_sync(db_operation_fn, params)

In one particular case I wrapped this sort of logic into a class with some error handling and other mechanisms to cache the result and prevent multiple invocations of the database query.

Closing due to the noted breakage not being possible anymore.

Danangsatriani commented 1 year ago

so whats the fix for this guys?