potiuk commented on PR #37638:
URL: https://github.com/apache/airflow/pull/37638#issuecomment-2015695912

   > ### Does not raise Valueerror
   
   When I run it in my unit test, I got Internal Server error - that's why it 
does not return ValueError, because it converts ValueError into 500 internal 
HTTP error:
   
   ```
   FAILED [100%][2024-03-22T19:17:02.835+0100] {exceptions.py:97} ERROR - 
ValueError("'dummy' is not a valid DagRunState")
   Traceback (most recent call last):
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/starlette/_exception_handler.py",
 line 53, in wrapped_app
       await app(scope, receive, sender)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/swagger_ui.py",
 line 222, in __call__
       await self.router(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/starlette/routing.py",
 line 756, in __call__
       await self.middleware_stack(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/starlette/routing.py",
 line 806, in app
       await self.default(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/swagger_ui.py",
 line 235, in default_fn
       await self.app(original_scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/starlette/middleware/cors.py",
 line 85, in __call__
       await self.app(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/routing.py",
 line 154, in __call__
       await self.router(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/starlette/routing.py",
 line 756, in __call__
       await self.middleware_stack(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/starlette/routing.py",
 line 806, in app
       await self.default(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/routing.py",
 line 48, in __call__
       await self.next_app(original_scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/abstract.py",
 line 268, in __call__
       await self.app(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/abstract.py",
 line 268, in __call__
       await self.app(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/abstract.py",
 line 268, in __call__
       await self.app(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/lifespan.py",
 line 26, in __call__
       await self.next_app(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/middleware/abstract.py",
 line 268, in __call__
       await self.app(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/connexion/apps/flask.py",
 line 151, in __call__
       return await self.asgi_app(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/a2wsgi/wsgi.py",
 line 165, in __call__
       return await responder(scope, receive, send)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/a2wsgi/wsgi.py",
 line 200, in __call__
       await self.loop.run_in_executor(
     File 
"/home/jarek/.local/share/hatch/pythons/3.8/python/lib/python3.8/concurrent/futures/thread.py",
 line 57, in run
       result = self.fn(*self.args, **self.kwargs)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/a2wsgi/wsgi.py",
 line 256, in wsgi
       iterable = self.app(environ, start_response)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/flask/app.py",
 line 2532, in wsgi_app
       response = self.handle_exception(e)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/flask/app.py",
 line 2529, in wsgi_app
       response = self.full_dispatch_request()
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/flask/app.py",
 line 1825, in full_dispatch_request
       rv = self.handle_user_exception(e)
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/flask/app.py",
 line 1823, in full_dispatch_request
       rv = self.dispatch_request()
     File 
"/home/jarek/.local/share/hatch/env/virtual/apache-airflow/AdTkC0pY/apache-airflow/lib/python3.8/site-packages/flask/app.py",
 line 1799, in dispatch_request
       return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
     File "/home/jarek/code/airflow/airflow/www/api/experimental/endpoints.py", 
line 54, in decorated
       return auth.requires_authentication(function)(*args, **kwargs)
     File "/home/jarek/code/airflow/airflow/api/auth/backend/default.py", line 
40, in decorated
       return function(*args, **kwargs)
     File "/home/jarek/code/airflow/airflow/www/api/experimental/endpoints.py", 
line 172, in dag_runs
       dagruns = get_dag_runs(dag_id, state)
     File 
"/home/jarek/code/airflow/airflow/api/common/experimental/get_dag_runs.py", 
line 43, in get_dag_runs
       state = DagRunState(state.lower()) if state else None
     File 
"/home/jarek/.local/share/hatch/pythons/3.8/python/lib/python3.8/enum.py", line 
339, in __call__
       return cls.__new__(cls, value)
     File 
"/home/jarek/.local/share/hatch/pythons/3.8/python/lib/python3.8/enum.py", line 
663, in __new__
       raise ve_exc
   ValueError: 'dummy' is not a valid DagRunState
   [2024-03-22T19:17:02.838+0100] {_client.py:1027} INFO - HTTP Request: GET 
http://testserver/api/experimental/dags/example_bash_operator/dag_runs?state=dummy
 "HTTP/1.1 500 Internal Server Error"
   ```
   
   It is likely a difference between how the application behaves in tests. You 
can see it when you do step-by-step debugging on what is going on with the test.
   
   1) In main (connexion 2):
   
   It looks like how app.get() works - it does not make the actual HTTP call - 
they start a WSGI application, pass the parameters and in case of exception, 
they do not return the actual HTTP error, but raise the exception returned by 
the WSGI call (so expect that this exception will be mapped to HTTP error above 
the get call. 
   
   2) in your PR:
   
   After moving to starlette and ASGI the same "get" method of the app wil 
actuallly run an http client to make the call (starlette/testclient.py) - seems 
that this test client derives from `httpx` library and actually makes an http 
call:
   
   
   
![image](https://github.com/apache/airflow/assets/595491/f734f4b7-8b05-4c2e-b2e7-44048472ce5f)
   
   
   So seems like somewhere, our integration with the API maps ValueError into 
Internal Server Error and the previous implementation was likely raising a 
Value Error to map it into a different HTTP Response. 
   
   
   So that's why we do not see a "ValueError". I think it's worth to check if 
in case of this particular API call we also eventually would get a 500 error (I 
guess so - experimental API was not very well tested nor did not have good 
error handling) and in this case we should simply convert them to check if the 
Response returned by get() is HTTP 500  
   


-- 
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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to