RazerM / sqlalchemy_aio

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

how to make metadata.reflect work? #13

Closed ZeeD closed 6 years ago

ZeeD commented 6 years ago

I cannot use the sqlalchemy.MetaData class, it seems to me that sqlalchemy expect a "syncronous" context manager

>>> metadata
MetaData(bind=TrioEngine<Engine(postgres+psycopg2://postgres:***@127.0.0.1:5432/postgres)>)
>>> metadata.reflect()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\vito.detullio\Desktop\workspace-photon\ita-dap-sf-extractor\.venv\lib\site-packages\sqlalchemy\sql\schema.py", line 3908, in reflect
    with bind.connect() as conn:
AttributeError: __enter__
RazerM commented 6 years ago

FYI bound metadata is discouraged in modern SQLAlchemy, it's recommended that the bind is given explicitly when you call e.g. reflect or create_all. Regardless, it won't work with the TrioEngine that you see in the repr.

The next release will make this much clearer when you try it, see CHANGELOG.md and the following error: https://github.com/RazerM/sqlalchemy_aio/blob/1f6af76ce4069bbda92ae97cdbb435367bd91534/sqlalchemy_aio/base.py#L508-L515

So you'll be able to do:

await engine.run_in_thread(metadata.reflect, engine.sync_engine)
ZeeD commented 6 years ago

ok thank you.

ZeeD commented 6 years ago

BTW: is already available a public schedule regarding the next release?

RazerM commented 6 years ago

Should be this week