-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rmtree not working when there is directory inside (google cloud storage) #184
Comments
@gadotroee Can you add the full stack trace and what the file structure on GCS looks like when you see the error? We do have a test that hits cloudpathlib/tests/test_cloudpath_file_io.py Lines 11 to 40 in de6b547
It would be good to know if this test case is missing a scenario we need to capture. Even better would be a minimally reproducible example using only |
Hi. @pjbull - Thanks for the quick reply. I tried simple script and it did work so I understand the issue is in my folder and the issue is that this folder has directories in it. so here is the full stack trace and example script (using cloudpathlib to created files and then rmtree to delete it): ipython test-cloud-path-lib.py
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
written file
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/Desktop/test-cloud-path-lib.py in <module>
15
16
---> 17 CloudPath(os.path.join(base_dir)).rmtree()
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cloudpathlib/cloudpath.py in rmtree(self)
612 f"Path {self} is a file; call unlink instead of rmtree."
613 )
--> 614 self.client._remove(self)
615
616 def upload_from(
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cloudpathlib/gs/gsclient.py in _remove(self, cloud_path)
189 bucket = self.client.bucket(cloud_path.bucket)
190 for blob in blobs:
--> 191 bucket.get_blob(blob).delete()
192 elif self._is_file_or_dir(cloud_path) == "file":
193 bucket = self.client.bucket(cloud_path.bucket)
AttributeError: 'NoneType' object has no attribute 'delete'
I hope this will help.. |
Thanks @gadotroee, I'll see if we can reproduce this. A couple little things on the script that you sent:
import os
from cloudpathlib import CloudPath
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path-to-json-credentials-file"
gcs_bucket_name = <bucket-name>
dir_name = 'example-dir'
base_dir = CloudPath(f"gs://{gcs_bucket_name}/{dir_name}")
base_dir.mkdir()
for sub_folder in ["test1", "test2"]:
for i in range(2):
(base_dir / sub_folder / f"{i}.txt").write_text(str(i))
print("written file")
base_dir.rmtree() |
I tested again with this script and it is very nice improvement, but as I think the reason is that I'm trying to delete folder that has folders inside. If I'm running the script (as is) it failed, but when I'm doing this the following little change Hope this will help to understand the reason and maybe add this as a test scenario. |
Repro'd this on both Azure and GCS. Problem is that |
@gadotroee this should be fixed in release |
Hi @pjbull , I tried to use the new version but I think something is broken there..
Is it issue in my environment or problem with version "0.6.3"? |
when I re-installed (with [all]) it is working (so the reason is missing package if azure.. |
Yep, thanks @gadotroee. Looks like a small issue introduced by #177. I've made the necessary fix and will update the releases once the test suite passes. |
@gadotroee ok, that issue should be fixed now in release |
This package is really helpful to work with different cloud providers but I'm facing an issue when trying to remove directory in gcs.
I tried it even in some test script using this line (after handle the authentication, because I do get True for methods like .exists() or is_dir().
CloudPath("gs://<bucket>/<path_to_folder(prefix)>").rmtree()
and getting exception from the _remove function. ('NoneType' object has no attribute 'delete').
Am I missing something in my usage or maybe it is knows bug?
Thanks
The text was updated successfully, but these errors were encountered: