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

ash pushed a commit to branch v3-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-1-test by this push:
     new 48f04ab6109 [v3-1-test] Fix exception when logging stdout with a 
custom %-fmt string. (#58959) (#58963)
48f04ab6109 is described below

commit 48f04ab610961f6d3e9dc81f8b293f93ede5484d
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Dec 2 18:06:54 2025 +0000

    [v3-1-test] Fix exception when logging stdout with a custom %-fmt string. 
(#58959) (#58963)
---
 .../src/airflow_shared/logging/percent_formatter.py        | 10 ++++++++++
 shared/logging/tests/logging/test_percent_formatter.py     | 14 ++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/shared/logging/src/airflow_shared/logging/percent_formatter.py 
b/shared/logging/src/airflow_shared/logging/percent_formatter.py
index b08024621e6..78e4b82a810 100644
--- a/shared/logging/src/airflow_shared/logging/percent_formatter.py
+++ b/shared/logging/src/airflow_shared/logging/percent_formatter.py
@@ -50,6 +50,16 @@ class _LazyLogRecordDict(collections.abc.Mapping):
         # Roughly compatible with names from 
https://github.com/python/cpython/blob/v3.13.7/Lib/logging/__init__.py#L571
         # Plus with ColoredLog added in
 
+        # If there is no callsite info (often for stdout/stderr), show the 
same sort of thing that stdlib
+        # logging would
+        # 
https://github.com/python/cpython/blob/d3c888b4ec15dbd7d6b6ef4f15b558af77c228af/Lib/logging/__init__.py#L1652C34-L1652C48
+        if key == "lineno":
+            return self.event.get("lineno", 0)
+        if key == "filename":
+            return self.event.get("filename", "(unknown file)")
+        if key == "funcName":
+            return self.event.get("funcName", "(unknown function)")
+
         if key in PercentFormatRender.callsite_parameters:
             return 
self.event.get(PercentFormatRender.callsite_parameters[key].value)
         if key == "name":
diff --git a/shared/logging/tests/logging/test_percent_formatter.py 
b/shared/logging/tests/logging/test_percent_formatter.py
new file mode 100644
index 00000000000..efcafd1353a
--- /dev/null
+++ b/shared/logging/tests/logging/test_percent_formatter.py
@@ -0,0 +1,14 @@
+from __future__ import annotations
+
+from unittest import mock
+
+from airflow_shared.logging.percent_formatter import PercentFormatRender
+
+
+class TestPercentFormatRender:
+    def test_no_callsite(self):
+        fmter = PercentFormatRender("%(filename)s:%(lineno)d %(message)s")
+
+        formatted = fmter(mock.Mock(name="Logger"), "info", {"event": "our 
msg"})
+
+        assert formatted == "(unknown file):0 our msg"

Reply via email to