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

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


The following commit(s) were added to refs/heads/v3-2-test by this push:
     new 8e24972d781 [v3-2-test] Fix #62414: Remove spurious blank lines in 
filtered task log download (#64235) (#64640)
8e24972d781 is described below

commit 8e24972d78127c718e59fdb03d8caace4cde842c
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Apr 6 11:33:10 2026 -0400

    [v3-2-test] Fix #62414: Remove spurious blank lines in filtered task log 
download (#64235) (#64640)
    
    * Fix #62414: Remove spurious blank lines in filtered task log download
    
    When log level or source filters were applied, renderStructuredLog returned
    empty strings for dropped lines. Joining those with newlines still
    inserted blank lines, often at the start of the downloaded file.
    
    * Fix prek formatting in Logs.tsx and logDownloadContent.test.ts
    
    Reformats getLogString arrow function to stay within line length limit,
    and fixes object key ordering (content before continuation_token) in
    test fixtures to match Prettier's alphabetical sorting.
    (cherry picked from commit 32ac5645c9eee1ec6fb7f6693d001099aadb9c91)
    
    Co-authored-by: Bernardo Gunzburger Lopes 
<[email protected]>
---
 .../ui/src/pages/TaskInstance/Logs/Logs.tsx        |   5 +-
 .../TaskInstance/Logs/logDownloadContent.test.ts   | 131 +++++++++++++++++++++
 2 files changed, 135 insertions(+), 1 deletion(-)

diff --git a/airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/Logs.tsx 
b/airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/Logs.tsx
index 681a92e68e3..c37b1e0b052 100644
--- a/airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/Logs.tsx
+++ b/airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/Logs.tsx
@@ -116,7 +116,10 @@ export const Logs = () => {
     );
   };
 
-  const getLogString = () => getParsedLogs().join("\n");
+  const getLogString = () =>
+    getParsedLogs()
+      .filter((line) => line !== "")
+      .join("\n");
 
   const downloadLogs = () => {
     const logContent = getLogString();
diff --git 
a/airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/logDownloadContent.test.ts
 
b/airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/logDownloadContent.test.ts
new file mode 100644
index 00000000000..84ccfbeaddb
--- /dev/null
+++ 
b/airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/logDownloadContent.test.ts
@@ -0,0 +1,131 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import type { TFunction } from "i18next";
+import { describe, expect, it } from "vitest";
+
+import type { TaskInstancesLogResponse } from "openapi/requests/types.gen";
+import { renderStructuredLog } from "src/components/renderStructuredLog";
+import { parseStreamingLogContent } from "src/utils/logs";
+
+/** Same construction as Logs.tsx getLogString (download path). */
+const logStringForDownload = (
+  fetchedData: TaskInstancesLogResponse | undefined,
+  logLevelFilters: Array<string>,
+  translate: TFunction,
+) =>
+  parseStreamingLogContent(fetchedData)
+    .map((line) =>
+      renderStructuredLog({
+        index: 0,
+        logLevelFilters,
+        logLink: "",
+        logMessage: line,
+        renderingMode: "text",
+        showSource: false,
+        showTimestamp: true,
+        sourceFilters: [],
+        translate,
+      }),
+    )
+    .filter((line) => line !== "")
+    .join("\n");
+
+describe("Task log download content (log level filter)", () => {
+  const translate = ((key: string) => key) as unknown as TFunction;
+
+  it("is empty when every structured line is excluded by the level filter", () 
=> {
+    const fetchedData: TaskInstancesLogResponse = {
+      content: [
+        {
+          event: "hello",
+          level: "info",
+          logger: "task.stdout",
+          timestamp: "2025-09-11T17:44:52.597476Z",
+        },
+      ],
+      continuation_token: null,
+    };
+
+    const text = logStringForDownload(fetchedData, ["error"], translate);
+
+    expect(text).toBe("");
+  });
+
+  it("is empty when structured lines have no level and any log level filter is 
set", () => {
+    const fetchedData: TaskInstancesLogResponse = {
+      content: [
+        {
+          event: "[timestamp] {file.py:1} INFO - legacy line without level 
field",
+          timestamp: "2025-02-28T10:49:09.679000+05:30",
+        },
+      ],
+      continuation_token: null,
+    };
+
+    const text = logStringForDownload(fetchedData, ["info"], translate);
+
+    expect(text).toBe("");
+  });
+
+  it("does not prefix the download with newlines when earlier lines are 
filtered out", () => {
+    const fetchedData: TaskInstancesLogResponse = {
+      content: [
+        {
+          event: "hidden-group-marker",
+          level: "debug",
+          logger: "task.stdout",
+          timestamp: "2025-09-11T17:44:52.597476Z",
+        },
+        {
+          event: "visible-line",
+          level: "info",
+          logger: "task.stdout",
+          timestamp: "2025-09-11T17:44:52.597500Z",
+        },
+      ],
+      continuation_token: null,
+    };
+
+    const text = logStringForDownload(fetchedData, ["info"], translate);
+
+    expect(text.startsWith("\n")).toBe(false);
+    expect(text).toContain("visible-line");
+    expect(text).not.toContain("hidden-group-marker");
+  });
+
+  it("includes matching structured lines when the filter matches level", () => 
{
+    const fetchedData: TaskInstancesLogResponse = {
+      content: [
+        {
+          event: "hello",
+          level: "info",
+          logger: "task.stdout",
+          timestamp: "2025-09-11T17:44:52.597476Z",
+        },
+      ],
+      continuation_token: null,
+    };
+
+    const text = logStringForDownload(fetchedData, ["info"], translate);
+
+    expect(text.length).toBeGreaterThan(0);
+    expect(text).toContain("hello");
+    expect(text).toContain("INFO");
+  });
+});

Reply via email to