Skip to content

Commit

Permalink
Ensure the "airflow.task" logger used for TaskInstancePydantic and Ta…
Browse files Browse the repository at this point in the history
…skInstance (#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 for TI anyway so I updated both.
  • Loading branch information
dstandish authored Mar 3, 2024
1 parent 5f4bf90 commit ede1912
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,7 @@ class TaskInstance(Base, LoggingMixin):
:meta private:
"""
_logger_name = "airflow.task"

def __init__(
self,
Expand Down Expand Up @@ -1435,8 +1436,6 @@ def insert_mapping(run_id: str, task: Operator, map_index: int) -> dict[str, Any
@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
Expand Down
4 changes: 4 additions & 0 deletions airflow/serialization/pydantic/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ede1912

Please sign in to comment.