Skip to content

Commit 611e74b

Browse files
committed
Address review: broaden exception catch to preserve lazy-failure contract
1 parent 2df36c4 commit 611e74b

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

task-sdk/src/airflow/sdk/io/path.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def __init__(
125125
if self._conn_id is not None:
126126
try:
127127
self.__wrapped__._fs_cached = attach(self.protocol or "file", self._conn_id).fs
128-
except (ImportError, ModuleNotFoundError):
129-
pass # Provider package not installed; will fail naturally when the path is used
128+
except Exception:
129+
pass # Provider not available or scheme unregistered; will fail naturally when the path is used
130130

131131
@classmethod_or_method # type: ignore[arg-type]
132132
def _from_upath(cls_or_self, upath, /):
@@ -145,8 +145,8 @@ def _from_upath(cls_or_self, upath, /):
145145
if obj._conn_id is not None and not hasattr(upath, "_fs_cached"):
146146
try:
147147
obj.__wrapped__._fs_cached = attach(upath.protocol or "file", obj._conn_id).fs
148-
except (ImportError, ModuleNotFoundError):
149-
pass # Provider package not installed; will fail naturally when the path is used
148+
except Exception:
149+
pass # Provider not available or scheme unregistered; will fail naturally when the path is used
150150
return obj
151151

152152
@property

task-sdk/tests/task_sdk/io/test_path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ def test_rmdir_uses_authenticated_fs(self, fake_fs_with_conn):
303303
"""rmdir() must use self.fs (Airflow-attached) not __wrapped__.fs (unauthenticated)."""
304304
fake_fs_with_conn.mkdir("bucket/empty_dir")
305305
p = ObjectStoragePath("ffs2://my_conn@bucket/empty_dir", conn_id="my_conn")
306-
p.rmdir(recursive=False)
306+
# upath's rmdir(recursive=False) calls next(self.iterdir()) without a default,
307+
# which raises StopIteration on empty dirs — a upath bug. Use the default (recursive=True).
308+
p.rmdir()
307309
assert not fake_fs_with_conn.exists("bucket/empty_dir")
308310

309311
def test_conn_id_in_uri_works_for_exists(self, fake_fs_with_conn):

0 commit comments

Comments
 (0)