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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Log of
list_folders
andlist_blobs
now displays bucket name and pathCloses #184.
When calling
list_folders
orlist_blobs
on aGcsBucket
the log message always displayedbucket_path
, a result of_join_bucket_folder
.If we are in the root directory however,
_join_bucket_folder
returnsNone
.If we hand a value for
folder
we receive the joined path.Changes made
Depending on wether
_join_bucket_folder
returnsNone
, which would mean we are listing from the root directory, we conditionally log a message containing the currentbucket_path
or justself.bucket
.I did not write tests for the log messages. If its needed, I will happily do so.
This will have to be discussed and I am happy to receive some guidance on this:
There exists a warning in the doc of
_join_bucket_folder
to be careful to not call it twice in nested method calls.With my implementation it is now called with the
folder
parameter inlist_folders
andlist_blobs
.Since
bucket_path
is not used in any other way inlist_folders
we should be fine.However, I see that this might lead to some bug down the road.
Thats why I wrote a warning comment.
This seemed to be the best approach to me, since other methods would have involved more conditional checking of
self.bucket_folder
/folder
inlist_folders
and combining them in some way in the message,which seemed to be too bloated just for a more sophisticated log message.
I also thought about
_resolve_path
, but it would lead to the same dangerous problem down the road and_join_bucket_folder
has a condition to check, if the method got called twice.If you prefer any of the mentioned methods or have a different idea, I am happy to implement it.
Example
When running this code:
The log output is:
When running this code:
The log output is:
When running
test_list_folders_with_subfolders
the log output is:Checklist
pre-commit
checks.pre-commit install && pre-commit run --all
locally for formatting and linting.mkdocs serve
view documentation locally.