diff --git a/airflow/io/path.py b/airflow/io/path.py index 709f50a316a84..87ab420b9c65e 100644 --- a/airflow/io/path.py +++ b/airflow/io/path.py @@ -361,3 +361,9 @@ def deserialize(cls, data: dict, version: int) -> ObjectStoragePath: conn_id = data.pop("conn_id", None) return ObjectStoragePath(path, conn_id=conn_id, **_kwargs) + + def __str__(self): + conn_id = self.storage_options.get("conn_id") + if self._protocol and conn_id: + return f"{self._protocol}://{conn_id}@{self.path}" + return super().__str__() diff --git a/tests/io/test_path.py b/tests/io/test_path.py index c08284163b835..1ccdfbfb79805 100644 --- a/tests/io/test_path.py +++ b/tests/io/test_path.py @@ -403,3 +403,8 @@ def test_lazy_load(self): assert o.fs is not None assert o._fs_cached + + @pytest.mark.parametrize("input_str", ("file:///tmp/foo", "s3://conn_id@bucket/test.txt")) + def test_str(self, input_str): + o = ObjectStoragePath(input_str) + assert str(o) == input_str