From 06477d6d06555d032f7cd52e878b94244eedb41a Mon Sep 17 00:00:00 2001 From: Daniel Standish <15932138+dstandish@users.noreply.github.com> Date: Tue, 22 Nov 2022 19:26:47 -0800 Subject: [PATCH 1/3] Don't log actions if db not initialized --- airflow/utils/cli_action_loggers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/airflow/utils/cli_action_loggers.py b/airflow/utils/cli_action_loggers.py index 17a4c4f890b22..be25e29439ce6 100644 --- a/airflow/utils/cli_action_loggers.py +++ b/airflow/utils/cli_action_loggers.py @@ -97,6 +97,8 @@ def default_action_log(sub_command, user, task_id, dag_id, execution_date, host_ :param **_: other keyword arguments that is not being used by this function :return: None """ + from sqlalchemy.exc import OperationalError, ProgrammingError + from airflow.models.log import Log from airflow.utils import timezone from airflow.utils.session import create_session @@ -121,8 +123,17 @@ def default_action_log(sub_command, user, task_id, dag_id, execution_date, host_ } ], ) - except Exception as error: - logging.warning("Failed to log action with %s", error) + except (OperationalError, ProgrammingError) as e: + expected = [ + '"log" does not exist', # postgres + "no such table", # sqlite + "log' doesn't exist", # mysql + "Invalid object name 'log'", # mssql + ] + if getattr(e, "args", None) and not any(x in e.args[0] for x in expected): + logging.warning("Failed to log action %s", e) + except Exception as e: + logging.error("Failed to log action %s", e) __pre_exec_callbacks: list[Callable] = [] From 216c1d6692af99d8263689248a9b71df314654e0 Mon Sep 17 00:00:00 2001 From: Daniel Standish <15932138+dstandish@users.noreply.github.com> Date: Tue, 22 Nov 2022 21:11:18 -0800 Subject: [PATCH 2/3] cleanup --- airflow/utils/cli_action_loggers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airflow/utils/cli_action_loggers.py b/airflow/utils/cli_action_loggers.py index be25e29439ce6..d6a8a13bb887d 100644 --- a/airflow/utils/cli_action_loggers.py +++ b/airflow/utils/cli_action_loggers.py @@ -130,10 +130,10 @@ def default_action_log(sub_command, user, task_id, dag_id, execution_date, host_ "log' doesn't exist", # mysql "Invalid object name 'log'", # mssql ] - if getattr(e, "args", None) and not any(x in e.args[0] for x in expected): + if e.args and not any(x in e.args[0] for x in expected): logging.warning("Failed to log action %s", e) except Exception as e: - logging.error("Failed to log action %s", e) + logging.warning("Failed to log action %s", e) __pre_exec_callbacks: list[Callable] = [] From e7cc5f3d6ed575d8dbfe50e3b3dcfd978a91414f Mon Sep 17 00:00:00 2001 From: Daniel Standish <15932138+dstandish@users.noreply.github.com> Date: Tue, 22 Nov 2022 21:15:28 -0800 Subject: [PATCH 3/3] cleanup --- airflow/utils/cli_action_loggers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airflow/utils/cli_action_loggers.py b/airflow/utils/cli_action_loggers.py index d6a8a13bb887d..0c93148308fbc 100644 --- a/airflow/utils/cli_action_loggers.py +++ b/airflow/utils/cli_action_loggers.py @@ -130,7 +130,8 @@ def default_action_log(sub_command, user, task_id, dag_id, execution_date, host_ "log' doesn't exist", # mysql "Invalid object name 'log'", # mssql ] - if e.args and not any(x in e.args[0] for x in expected): + error_is_ok = e.args and any(x in e.args[0] for x in expected) + if not error_is_ok: logging.warning("Failed to log action %s", e) except Exception as e: logging.warning("Failed to log action %s", e)