Skip to content
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

Make list backfills endpoint use asyncio #44208

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dstandish
Copy link
Contributor

@dstandish dstandish commented Nov 20, 2024

This is a sort of hello world / proof of concept for having an route implemented using asyncio.

Depends on #44226

@dstandish dstandish changed the title Make list backfills endpoint use async Make list backfills endpoint use asyncio Nov 20, 2024
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice.

Just a few small suggestions.

Also I realized that we cannot have 'lazy' loading of some attributes at serialization time (when using pydantic), because this will be 'uncontroled async I/O'.

I don't know if you are encountering this on the Backfill model, but basically it means that everything needs to be eager loaded before, so pydantic does not emit uncontrolled request afterwards. (and unfortunatly we cannot await BackfillResponse.model_validate)

Also just to mention that there is a stream API to iterate over multiple results. That could be interesting to see if this can help us here.

airflow/api_fastapi/common/db/common.py Outdated Show resolved Hide resolved
airflow/api_fastapi/common/db/common.py Outdated Show resolved Hide resolved
Given that sometimes we don't want to apply any filters, it makes sense to make the param optional.  I also fix the typing on `paginated_select`.
This is a sort of hello world for having an route implemented using asyncio.
@@ -498,7 +498,7 @@ def configure_orm(disable_connection_pool=False, pool_class=None):

engine = create_engine(SQL_ALCHEMY_CONN, connect_args=connect_args, **engine_args, future=True)
async_engine = create_async_engine(SQL_ALCHEMY_CONN_ASYNC, future=True)
create_async_session = sessionmaker(
session_maker_async = sessionmaker(
Copy link
Member

@pierrejeambrun pierrejeambrun Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your name is more explicit, and I understand why legacy names can feel confusing and this one could be better. (We call a session_maker Session oO => but that's actually a factory for session, so from the client code perspective we are constructing a session and we think we are manipulating a Session class for instantiation, that's especially true for the threadlocal registry scoped_session, just create a Session but actually things happen under the hood, we are not just instantiating a session and we don't ask people to explicitely use a factory, just the normal Session, that's how sqlalchemy docs and many other documents online recommend to do it.)

Anyway, for consistency, I recommend using AsyncSession. (same way as Session and NonScopedSession above).

In the user code this it just becomes session = AsyncSession()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to clarify, with this

that's how sqlalchemy docs and many other documents online recommend to do it

you are saying that the SA docs recommend doing it by storing session factory as AsyncSession, like we did with Session?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants