This is an automated email from the ASF dual-hosted git repository. ash pushed a commit to branch v2-0-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 62725cea85b8636791f76710bfc538d3d22deab5 Author: Ash Berlin-Taylor <[email protected]> AuthorDate: Thu Feb 25 13:25:04 2021 +0000 Fix logging error with task error when JSON logging is enabled (#14456) If the JSON logging mode for Elasticsearch logs is enabled, the handle_failure function would fail, as it tried to treat the exception object as the message and try to JSON serialize it (it expected a string) -- which fails with: ``` TypeError: Object of type type is not JSON serializable ... File "/usr/local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 1150, in handle_failure self.log.exception(error) ... File "/usr/local/lib/python3.7/site-packages/airflow/utils/log/file_task_handler.py", line 63, in emit self.handler.emit(record) ``` (cherry picked from commit 258ec5d95e98eac09ecc7658dcd5226c9afe14c6) --- airflow/models/taskinstance.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py index ed7a0be..119116e 100644 --- a/airflow/models/taskinstance.py +++ b/airflow/models/taskinstance.py @@ -1478,7 +1478,10 @@ class TaskInstance(Base, LoggingMixin): # pylint: disable=R0902,R0904 test_mode = self.test_mode if error: - self.log.exception(error) + if isinstance(error, Exception): + self.log.exception("Task failed with exception") + else: + self.log.error("%s", error) # external monitoring process provides pickle file so _run_raw_task # can send its runtime errors for access by failure callback if error_file:
