This is an automated email from the ASF dual-hosted git repository. kaxilnaik pushed a commit to branch v3-1-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 93dd13afbc0fd8a36331450ce9796222ef19c416 Author: Mikhail Ilchenko <[email protected]> AuthorDate: Mon Oct 27 00:19:54 2025 +0400 Fix iterating through `ObjectStoragePath` (#57156) (cherry picked from commit 4962b353d9e8d56a037ed37af4d818aea83d3cd5) --- task-sdk/src/airflow/sdk/io/path.py | 5 +++++ task-sdk/tests/task_sdk/io/test_path.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/task-sdk/src/airflow/sdk/io/path.py b/task-sdk/src/airflow/sdk/io/path.py index 5b66e09d110..611dfe2c8df 100644 --- a/task-sdk/src/airflow/sdk/io/path.py +++ b/task-sdk/src/airflow/sdk/io/path.py @@ -60,6 +60,11 @@ class _TrackingFileWrapper: return wrapper + # We need to explicitly implement `__iter__` + # because otherwise python iteration logic could use `__getitem__` + def __iter__(self): + return iter(self._obj) + def __getitem__(self, key): # Intercept item access return self._obj[key] diff --git a/task-sdk/tests/task_sdk/io/test_path.py b/task-sdk/tests/task_sdk/io/test_path.py index a85517a1ad4..027dc416014 100644 --- a/task-sdk/tests/task_sdk/io/test_path.py +++ b/task-sdk/tests/task_sdk/io/test_path.py @@ -215,6 +215,15 @@ class TestLocalPath: assert o.open("rb").read() == b"foo" o.unlink() + def test_read_line_by_line(self, target): + o = ObjectStoragePath(f"file://{target}") + with o.open("wb") as f: + f.write(b"foo\nbar\n") + with o.open("rb") as f: + lines = list(f) + assert lines == [b"foo\n", b"bar\n"] + o.unlink() + def test_stat(self, target): o = ObjectStoragePath(f"file://{target}") assert o.stat().st_size == 0
