Skip to content

exists raises on bucket that doesn't exist #519

Closed

Description

@jrbourbeau

This was originally posted in dask/dask#8056, see that issue for additional context

That's a fair point, here's what I've been able to come up with

import s3fs

fs = s3fs.S3FileSystem(anon=True)
# This directory exists
good_path = "s3://nyc-tlc/trip data/"
print(f"{fs.exists(good_path) = }")
print(f"{fs.isdir(good_path) = }")

# This bucket doesn't exist
bad_path = "s3://nyc-tlc-asdfasdf/trip data/"
print(f"{fs.exists(bad_path) = }")
print(f"{fs.isdir(bad_path) = }")

when I run this locally I get the following

fs.exists(good_path) = True
fs.isdir(good_path) = True
fs.exists(bad_path) = False
Traceback (most recent call last):
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/s3fs/core.py", line 574, in _lsdir
    async for i in it:
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/aiobotocore/paginate.py", line 32, in __anext__
    response = await self._make_request(current_kwargs)
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/aiobotocore/client.py", line 155, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the ListObjectsV2 operation: The specified bucket does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/james/projects/dask/dask/s3test.py", line 13, in <module>
    print(f"{fs.isdir(bad_path) = }")
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/fsspec/asyn.py", line 88, in wrapper
    return sync(self.loop, func, *args, **kwargs)
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/fsspec/asyn.py", line 69, in sync
    raise result[0]
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/fsspec/asyn.py", line 25, in _runner
    result[0] = await coro
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/s3fs/core.py", line 1161, in _isdir
    return bool(await self._lsdir(path))
  File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/s3fs/core.py", line 597, in _lsdir
    raise translate_boto_error(e)
FileNotFoundError: The specified bucket does not exist

Note that fs.exists(bad_path) returns False, while fs.isdir(bad_path) raises a FileNotFoundError: The specified bucket does not exist error. This is the type of discrepancy I was running into earlier with to_parquet + overwrite=True and what motivated me proposing the fs.exists check in dask/dask#8057.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions