Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fixing empty logging in list_folders and list_blobs #214

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix `list_folders` and `list_blobs` now logging bucket name and bucket path - [#184](https://github.com/PrefectHQ/prefect-gcp/pull/214)

### Security

## 0.4.7
Expand Down
20 changes: 16 additions & 4 deletions prefect_gcp/cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,12 @@ async def list_blobs(self, folder: str = "") -> List["Blob"]:
client = self.gcp_credentials.get_cloud_storage_client()

bucket_path = self._join_bucket_folder(folder)
self.logger.info(f"Listing blobs in bucket {bucket_path}.")
if bucket_path is None:
self.logger.info(f"Listing blobs in bucket {self.bucket!r}.")
else:
self.logger.info(
f"Listing blobs in folder {bucket_path!r} in bucket {self.bucket!r}."
)
blobs = await run_sync_in_worker_thread(
client.list_blobs, self.bucket, prefix=bucket_path
)
Expand Down Expand Up @@ -903,12 +908,19 @@ async def list_folders(self, folder: str = "") -> List[str]:
from prefect_gcp.cloud_storage import GcsBucket

gcs_bucket = GcsBucket.load("my-bucket")
gcs_bucket.list_folders('years)
gcs_bucket.list_folders("years")
```
"""

bucket_path = self._join_bucket_folder()
self.logger.info(f"Listing folders in bucket {bucket_path}.")
# Beware of calling _join_bucket_folder twice, see note in method.
# However, we just want to use it to check if we are listing the root folder
bucket_path = self._join_bucket_folder(folder)
if bucket_path is None:
self.logger.info(f"Listing folders in bucket {self.bucket!r}.")
else:
self.logger.info(
f"Listing folders in {bucket_path!r} in bucket {self.bucket!r}."
)

blobs = await self.list_blobs(folder)
# gets all folders with full path
Expand Down