cloudpathlib icon indicating copy to clipboard operation
cloudpathlib copied to clipboard

reset_default_storage_dir gets ignored through get_default_client

Open Quickblink opened this issue 1 year ago • 1 comments

from cloudpathlib.local import LocalS3Path, LocalS3Client

path = LocalS3Path("s3://some/path/")
path.touch()
LocalS3Client.reset_default_storage_dir()
new_path = LocalS3Path("s3://some/path/")
assert not new_path.is_file() # fails

The reason is that reset_default_storage_dir() acts on the class attribute only and not on the instance attribute of the LocalClient in question. Because of Client.get_default_client() returning the same client instance for any path (saved as a class attribute), no new client gets instantiated to make use of the new directory. The tests don’t catch that because they create the clients explicitly.

Quickblink avatar Mar 02 '24 11:03 Quickblink

Thanks @Quickblink, this seems like a real bug.

I believe the easiest way to fix this is to call get_default_client inside reset_default_storage_dir and then also call reset_default_storage_dir on that instance of the client.

pjbull avatar Mar 02 '24 18:03 pjbull