VladaZakharova commented on PR #36052:
URL: https://github.com/apache/airflow/pull/36052#issuecomment-1849644073

   > Thanks @VladaZakharova.
   > 
   > I believe we'll need to take a slightly different approach though. We only 
want to create a single `FlaskApp` and register `Apis` on them. I left some 
comments.
   > 
   > As mentioned, I started an effort to port to Connexion 3 a couple of weeks 
ago, but didn't have the time to complete it. I pushed my changes 
[here](https://github.com/RobbeSneyders/airflow/pull/1/files) so you can have a 
look.
   
   Thank you for your suggestions! I also checked your PR you have mentioned 
and i can say we are almost there! :D
   I think the best approach here will be to let Robbe create PR in Community 
with his changes, since all the migration on Apache Airflow side was covered in 
his PR. 
   I was also able to test changes with new Gunicorn command to use ASGI as was 
suggested earlier also by Robbe and i can see that Airflow is actually working 
in breeze, but when clicking something in the UI i can see this error:
   ```
   webserver  | [2023-12-07 10:27:48 +0000] [1312734] [ERROR] Exception in ASGI 
application
   webserver  | Traceback (most recent call last):
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 
164, in __call__
   webserver  | await self.app(scope, receive, _send)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/connexion/middleware/exceptions.py", 
line 101, in __call__
   webserver  | await super().__call__(scope, receive, send)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/starlette/middleware/exceptions.py", 
line 62, in __call__
   webserver  | await wrap_app_handling_exceptions(self.app, conn)(scope, 
receive, send)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/starlette/_exception_handler.py", line 
63, in wrapped_app
   webserver  | response = await handler(conn, exc)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/connexion/middleware/exceptions.py", 
line 39, in wrapper
   webserver  | response = await run_in_threadpool(handler, request, exc)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 35, in 
run_in_threadpool
   webserver  | return await anyio.to_thread.run_sync(func, *args)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/anyio/to_thread.py", line 49, in 
run_sync
   webserver  | return await get_async_backend().run_sync_in_worker_thread(
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 
2103, in run_sync_in_worker_thread
   webserver  | return await future
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 823, 
in run
   webserver  | result = context.run(func, *args)
   webserver  | File "/opt/airflow/airflow/www/extensions/init_views.py", line 
229, in _handle_api_not_found
   webserver  | return views.not_found(ex)
   webserver  | File "/opt/airflow/airflow/www/views.py", line 632, in not_found
   webserver  | render_template(
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/flask/templating.py", line 145, in 
render_template
   webserver  | app = current_app._get_current_object()  # type: 
ignore[attr-defined]
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/werkzeug/local.py", line 508, in 
_get_current_object
   webserver  | raise RuntimeError(unbound_message) from None
   webserver  | RuntimeError: Working outside of application context.
   webserver  | This typically means that you attempted to use functionality 
that needed
   webserver  | the current application. To solve this, set up an application 
context
   webserver  | with app.app_context(). See the documentation for more 
information.
   webserver  | During handling of the above exception, another exception 
occurred:
   webserver  | Traceback (most recent call last):
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", 
line 408, in run_asgi
   webserver  | result = await app(  # type: ignore[func-returns-value]
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", 
line 84, in __call__
   webserver  | return await self.app(scope, receive, send)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/connexion/apps/abstract.py", line 284, 
in __call__
   webserver  | return await self.middleware(scope, receive, send)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/connexion/middleware/main.py", line 
501, in __call__
   webserver  | await self.app(scope, receive, send)
   webserver  | File 
"/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 
181, in __call__
   webserver  | await response(scope, receive, send)
   webserver  | TypeError: 'coroutine' object is not callable
   webserver  | 192.168.11.1:48504 - "GET /static/clusterActivity.js HTTP/1.1" 
500
   ```
   
   I think it is connected to the fact that we are trying now to run 
synchronous methods asynchronously, so we are failing :D
   Maybe guys you can suggest something regarding this? Should we rewrite all 
the calls that are synchronous or there are other approaches to solve this 
problem?
   
   The final Gunicorn command i was using is:
   ```
   run_args = [
               sys.executable,
               "-m",
               "gunicorn",
               "-k",
               "uvicorn.workers.UvicornWorker",
               "--workers",
               str(num_workers),
               "--timeout",
               str(worker_timeout),
               "--bind",
               args.hostname + ":" + str(args.port),
               "--name",
               "airflow-webserver",
               "--pid",
               pid_file,
               "--config",
               "python:airflow.www.gunicorn_config",
           ]
   ```
   Thank you!
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to