fat-catTW commented on code in PR #69267:
URL: https://github.com/apache/airflow/pull/69267#discussion_r3524244361
##########
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}"
+ statement = str(statement)
+ orig_error = str(orig_error)
Review Comment:
I didn't apply this suggestion because `statement` is still used by
`log.exception()` before the `if` block. Moving its initialization into the if
block would result in `statement` being undefined when `log.exception() is
called.
--
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]