-
Notifications
You must be signed in to change notification settings - Fork 382
Writing to a new file in an existing bucket throws "unspecified location constraint" error as it incorrectly tries to create new bucket #1404
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
Comments
This has come up in previous issues. Essentially, it is right to try to create the bucket in this case (accepting auto_mkdir), since s3 doesn't provide a guaranteed way to know whether the bucket exists. I suggest that makedirs should
Alternatively, in fsspec.core, we could write the file whether or not the mkdirs succeeds, and provide an informative message if that then fails in turn. |
The problem with this approach is that in a production environment, it is unlikely that permission for create bucket has been granted to the service account, only permission to write new files. From the following Stack Overflow threads, there are a few alternatives suggested to check whether an S3 bucket already exists:
Perhaps one of these alternatives can be used instead to check whether the S3 bucket already exists, to prevent running into errors when trying to create an S3 bucket (when we already knows it exists beforehand)? |
Indeed, an HTTP HEAD call to f"https://{bucket}.s3.amazonaws.com" is enough to ascertain if it exists or not (not going to use boto3!). But why would this be any faster than trying to create the bucket and failing? |
You're right in that it wouldn't be any faster. What I'm suggesting is, if I only want to write a file to an S3 bucket that already exists, it should not fail when I have permission to write a file but not permission to create a bucket. Whether we use an alternative way to check for an S3 bucket that already exists, or we try to create the bucket but catch permission-related errors is fine by me but in the latter case we would still need an alternative way to check whether the bucket exists or not unless we just proceed with attempting to write the file anyway. Alternatively, there could be a different flag which controls whether to check if the bucket exists before attempting to write to a file in it. |
yes, this was one of my suggestions. Would you like to contribute the change?
You can already opt out of the behaviour with auto_mkdir=False |
Thanks Martin. I've attempted to address this issue by opening the following PR: Comments on how to improve the PR will be most welcome 🙂 |
Writing to a new file in an existing bucket throws "unspecified location constraint" error as it incorrectly tries to create new bucket
Problem
Using the current latest versions of
fsspec
ands3fs
i.e.2023.10.0
, when I tried to write to a new file inside a "subdirectory" in S3 that didn't exist yet via:I got this error, even though the S3 bucket already exists:
This happens because of the parameter
auto_mkdir=True
in theopen_files()
function here.Workaround
I managed to resolve this error by changing the command to the following, i.e. adding
auto_mkdir=False
as a kwarg:The text was updated successfully, but these errors were encountered: