You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "pierrejeambrun (via GitHub)" <gi...@apache.org> on 2025/09/29 15:49:07 UTC
[PR] Fix fastapi new version issue [airflow]
pierrejeambrun opened a new pull request, #56214:
URL: https://github.com/apache/airflow/pull/56214
I would like to fix the 'hard coded' string there. Some more small change might come, lets see if CI is happy.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix fastapi new version issue [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #56214:
URL: https://github.com/apache/airflow/pull/56214#discussion_r2388469644
##########
airflow-core/src/airflow/api_fastapi/common/router.py:
##########
@@ -43,3 +52,52 @@ def decorator(func: DecoratedCallable) -> DecoratedCallable:
return func
return decorator
+
+
+def _route_uses_dep(route: APIRoute, *, module: str, name: str) -> bool:
+ stack = list(route.dependant.dependencies)
+ while stack:
+ dep = stack.pop()
+ call = getattr(dep, "call", None)
+ if call is not None:
+ mod = getattr(call, "__module__", "")
+ func_name = getattr(call, "__name__", "")
+ if mod == module and func_name == name:
+ return True
+ stack.extend(getattr(dep, "dependencies", []) or [])
+ return False
+
+
+class _AirflowRoute(APIRoute):
+ def get_route_handler(self) -> Callable[[Request], Coroutine[None, None, Response]]:
+ default_handler = super().get_route_handler()
+ uses_sync = _route_uses_dep(self, module="airflow.api_fastapi.common.db.common", name="_get_session")
+ uses_async = _route_uses_dep(
+ self, module="airflow.api_fastapi.common.db.common", name="_get_async_session"
+ )
+
+ async def handler(request: Request) -> Response:
+ if not (uses_sync or uses_async):
+ return await default_handler(request)
+ if uses_async:
+ async with create_session_async() as async_session:
+ setattr(request.state, "__airflow_async_db_session", async_session)
+ response = await default_handler(request)
+ await async_session.commit()
+ try:
+ delattr(request.state, "__airflow_async_db_session")
+ except Exception:
+ pass
+ return response
Review Comment:
to remove
##########
airflow-core/src/airflow/api_fastapi/common/router.py:
##########
@@ -43,3 +52,52 @@ def decorator(func: DecoratedCallable) -> DecoratedCallable:
return func
return decorator
+
+
+def _route_uses_dep(route: APIRoute, *, module: str, name: str) -> bool:
+ stack = list(route.dependant.dependencies)
+ while stack:
+ dep = stack.pop()
+ call = getattr(dep, "call", None)
+ if call is not None:
+ mod = getattr(call, "__module__", "")
+ func_name = getattr(call, "__name__", "")
+ if mod == module and func_name == name:
+ return True
+ stack.extend(getattr(dep, "dependencies", []) or [])
+ return False
+
+
+class _AirflowRoute(APIRoute):
+ def get_route_handler(self) -> Callable[[Request], Coroutine[None, None, Response]]:
+ default_handler = super().get_route_handler()
+ uses_sync = _route_uses_dep(self, module="airflow.api_fastapi.common.db.common", name="_get_session")
+ uses_async = _route_uses_dep(
+ self, module="airflow.api_fastapi.common.db.common", name="_get_async_session"
+ )
+
+ async def handler(request: Request) -> Response:
+ if not (uses_sync or uses_async):
+ return await default_handler(request)
+ if uses_async:
+ async with create_session_async() as async_session:
+ setattr(request.state, "__airflow_async_db_session", async_session)
+ response = await default_handler(request)
+ await async_session.commit()
+ try:
+ delattr(request.state, "__airflow_async_db_session")
+ except Exception:
+ pass
+ return response
+ else:
+ with create_session(scoped=False) as session:
+ setattr(request.state, "__airflow_db_session", session)
+ response = await default_handler(request)
+ session.commit()
+ try:
+ delattr(request.state, "__airflow_db_session")
+ except Exception:
+ pass
+ return response
Review Comment:
to remove
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix fastapi new version issue [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #56214:
URL: https://github.com/apache/airflow/pull/56214#issuecomment-3350086627
That one looks very ugly, non-obvious, almost magical, and - to be honest - it is one big hack (and seems it still does not work :( ). I would say we should raise an issue and ask Sebastian to add a way to mark some of dependencies to be finalized early and limit the fast_api until it's done.
I do not know fast_api that well, but simple `Depends(_get_session, finalize_early=True)` should do the job.
I think we can point to this PR to Sebastian to show our use case and justify the need for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix fastapi new version issue [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #56214:
URL: https://github.com/apache/airflow/pull/56214#discussion_r2388614495
##########
airflow-core/src/airflow/api_fastapi/common/router.py:
##########
@@ -43,3 +52,52 @@ def decorator(func: DecoratedCallable) -> DecoratedCallable:
return func
return decorator
+
+
+def _route_uses_dep(route: APIRoute, *, module: str, name: str) -> bool:
+ stack = list(route.dependant.dependencies)
+ while stack:
+ dep = stack.pop()
+ call = getattr(dep, "call", None)
+ if call is not None:
+ mod = getattr(call, "__module__", "")
+ func_name = getattr(call, "__name__", "")
+ if mod == module and func_name == name:
+ return True
+ stack.extend(getattr(dep, "dependencies", []) or [])
+ return False
+
+
+class _AirflowRoute(APIRoute):
+ def get_route_handler(self) -> Callable[[Request], Coroutine[None, None, Response]]:
+ default_handler = super().get_route_handler()
+ uses_sync = _route_uses_dep(self, module="airflow.api_fastapi.common.db.common", name="_get_session")
+ uses_async = _route_uses_dep(
+ self, module="airflow.api_fastapi.common.db.common", name="_get_async_session"
+ )
+
+ async def handler(request: Request) -> Response:
+ if not (uses_sync or uses_async):
+ return await default_handler(request)
+ if uses_async:
+ async with create_session_async() as async_session:
+ setattr(request.state, "__airflow_async_db_session", async_session)
+ response = await default_handler(request)
+ await async_session.commit()
+ try:
+ delattr(request.state, "__airflow_async_db_session")
+ except Exception:
+ pass
+ return response
Review Comment:
Done
##########
airflow-core/src/airflow/api_fastapi/common/router.py:
##########
@@ -43,3 +52,52 @@ def decorator(func: DecoratedCallable) -> DecoratedCallable:
return func
return decorator
+
+
+def _route_uses_dep(route: APIRoute, *, module: str, name: str) -> bool:
+ stack = list(route.dependant.dependencies)
+ while stack:
+ dep = stack.pop()
+ call = getattr(dep, "call", None)
+ if call is not None:
+ mod = getattr(call, "__module__", "")
+ func_name = getattr(call, "__name__", "")
+ if mod == module and func_name == name:
+ return True
+ stack.extend(getattr(dep, "dependencies", []) or [])
+ return False
+
+
+class _AirflowRoute(APIRoute):
+ def get_route_handler(self) -> Callable[[Request], Coroutine[None, None, Response]]:
+ default_handler = super().get_route_handler()
+ uses_sync = _route_uses_dep(self, module="airflow.api_fastapi.common.db.common", name="_get_session")
+ uses_async = _route_uses_dep(
+ self, module="airflow.api_fastapi.common.db.common", name="_get_async_session"
+ )
+
+ async def handler(request: Request) -> Response:
+ if not (uses_sync or uses_async):
+ return await default_handler(request)
+ if uses_async:
+ async with create_session_async() as async_session:
+ setattr(request.state, "__airflow_async_db_session", async_session)
+ response = await default_handler(request)
+ await async_session.commit()
+ try:
+ delattr(request.state, "__airflow_async_db_session")
+ except Exception:
+ pass
+ return response
+ else:
+ with create_session(scoped=False) as session:
+ setattr(request.state, "__airflow_db_session", session)
+ response = await default_handler(request)
+ session.commit()
+ try:
+ delattr(request.state, "__airflow_db_session")
+ except Exception:
+ pass
+ return response
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix fastapi new version issue [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #56214:
URL: https://github.com/apache/airflow/pull/56214#issuecomment-3351734567
> Yeah it seems that this is not working. Maybe for short term, we just limit the fastapi to unblock PRs and then revisit this with Sebastian
It works, I tested it locally, but the execution api doesn't load the middleware, so I would have to fix that.
I agree that this is not the best approach, and we should hold off before making our way around that incompatibility problem.
I'll close,lets see if fastapi comes up with a solution in the next releases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix fastapi new version issue [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun closed pull request #56214: Fix fastapi new version issue
URL: https://github.com/apache/airflow/pull/56214
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix fastapi new version issue [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #56214:
URL: https://github.com/apache/airflow/pull/56214#issuecomment-3350094472
Yeah it seems that this is not working. Maybe for short term, we just limit the fastapi to unblock PRs and then revisit this with Sebastian
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org