Hello, I am trying to use server-side cursors wit...
# prefect-cloud
c
Hello, I am trying to use server-side cursors with prefect-sqlalchemy and am unable to get it to work. Code fragment:
Copy code
query = f"SELECT * FROM `{table}`"
    print(f"Starting DB fetch")
    with conn_obj.get_engine().connect() as connection:
        print(f"Got DB connection")
        with connection.execution_options(yield_per=yield_per).execute(query) as result:
            print("Ran DB Query")
            print(f"sending block partition")
            time.sleep(1)
            for block in result:
                p_in.send(block)
...
fails with error
Copy code
AttributeError: __enter__
This type of error suggests that context manager is not supported - but it it is if SQLAlchemy is version 2. But my
pip freeze
reports
prefect-sqlalchemy==0.3.2
Can someone please assist? 1. What version of SQLAlchemy is prefect-sqlalchemy built over? 2. How do I do server-side cursors with Prefect SQLAlchemy?
c
Hi Cormac, one of our contributors added support for SQLAlchemy 2 in version 0.4.0: https://github.com/PrefectHQ/prefect-sqlalchemy/releases/tag/v0.4.0