This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new ede1912615 Ensure the "airflow.task" logger used for 
TaskInstancePydantic and TaskInstance (#37857)
ede1912615 is described below

commit ede19126150154c4435b5c114349a6ec77803cd5
Author: Daniel Standish <[email protected]>
AuthorDate: Sat Mar 2 22:32:24 2024 -0800

    Ensure the "airflow.task" logger used for TaskInstancePydantic and 
TaskInstance (#37857)
    
    Airflow TIs are assumed to log to the "airflow.task" logger.  TaskInstance 
was configuring this in the "reconstructor", a sqlalchemy thing that is 
processed on loading from DB.  But there's no equivalent for Pydantic models, 
and when running a task with TaskInstancePydantic, the wrong logger was used 
(fully qualified class name).  When looking for a solution, I saw that 
LoggingMixin will check `_logger_name` and if set will use it.  This works for 
the pydantic model and seems better f [...]
---
 airflow/models/taskinstance.py                 | 3 +--
 airflow/serialization/pydantic/taskinstance.py | 4 ++++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py
index d37a3be5ac..1b77a71ac7 100644
--- a/airflow/models/taskinstance.py
+++ b/airflow/models/taskinstance.py
@@ -1334,6 +1334,7 @@ class TaskInstance(Base, LoggingMixin):
 
     :meta private:
     """
+    _logger_name = "airflow.task"
 
     def __init__(
         self,
@@ -1435,8 +1436,6 @@ class TaskInstance(Base, LoggingMixin):
     @reconstructor
     def init_on_load(self) -> None:
         """Initialize the attributes that aren't stored in the DB."""
-        # correctly config the ti log
-        self._log = logging.getLogger("airflow.task")
         self.test_mode = False  # can be changed when calling 'run'
 
     @hybrid_property
diff --git a/airflow/serialization/pydantic/taskinstance.py 
b/airflow/serialization/pydantic/taskinstance.py
index 2830618d56..a818e3b3b3 100644
--- a/airflow/serialization/pydantic/taskinstance.py
+++ b/airflow/serialization/pydantic/taskinstance.py
@@ -114,6 +114,10 @@ class TaskInstancePydantic(BaseModelPydantic, 
LoggingMixin):
 
     model_config = ConfigDict(from_attributes=True, 
arbitrary_types_allowed=True)
 
+    @property
+    def _logger_name(self):
+        return "airflow.task"
+
     def init_run_context(self, raw: bool = False) -> None:
         """Set the log context."""
         self.raw = raw

Reply via email to