cloudpathlib
cloudpathlib copied to clipboard
reset_default_storage_dir gets ignored through get_default_client
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.
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.