henry3260 commented on code in PR #69267:
URL: https://github.com/apache/airflow/pull/69267#discussion_r3518335790


##########
airflow-core/src/airflow/api_fastapi/common/exceptions.py:
##########
@@ -170,8 +170,44 @@ def exception_handler(self, request: Request, exc: 
DeserializationError):
         )
 
 
+class SQLAlchemyErrorHandler(BaseErrorHandler[SQLAlchemyError]):
+    """Generic handler for SQLAlchemyError -> 500 responses."""
+
+    def __init__(self):
+        super().__init__(SQLAlchemyError)
+
+    def exception_handler(self, request: Request, exc: SQLAlchemyError):
+        exception_id = get_random_string()
+        # SQLAlchemyError may not have statement/orig attributes; guard access
+        statement = getattr(exc, "statement", "hidden")
+        orig_error = getattr(exc, "orig", "hidden")
+        log.exception("Error with id %s, statement: %s", exception_id, 
statement, exc_info=exc)
+        if conf.get("api", "expose_stacktrace") == "True":
+            message = f"Error with id {exception_id}, statement: {statement}"

Review Comment:
   I think we should match the `_DatabaseErrorHandler `behavior. When 
`expose_stacktrace=True`, we should include the traceback in the message.



##########
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py:
##########


Review Comment:
   Could we add a similar route-level test for 
`/execution/task-instances/{id}/run`? This PR changes both `ti_update_state` 
and `ti_run`, but only `/state` seems to assert the new 500 detail format for 
`SQLAlchemyError`.



-- 
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