Skip to content
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

S3 Create bucket doesn't throw an error when bucket already exists #4278

Closed
ash-murphy-colibri opened this issue Sep 19, 2024 · 1 comment
Closed
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.

Comments

@ash-murphy-colibri
Copy link

ash-murphy-colibri commented Sep 19, 2024

Describe the bug

When running the s3 client's create bucket method no exception is thrown when the bucket already exists. I also tried changing the region from eu-west-1 to eu-west-2 (by using Loc. Constraints) but still no exception is being raised.

The image below is the unit test, you'll see in the console the bucket exists.

Screenshot 2024-09-19 at 09 56 05

This is the code I would expect to throw an error:

      try:
        if deployment_region == "us-east-1":
            s3.create_bucket(ACL="private", Bucket=bucket_name)
        else:
            s3.create_bucket(
                ACL="private",
                Bucket=bucket_name,
                CreateBucketConfiguration={"LocationConstraint": deployment_region},
            )

Expected Behavior

I expected BucketAlreadyExists exception to be raised.

Current Behavior

No issues, response is 200.

Please note, this happens immediately after upgrading from version 4 to 5.0.14

Reproduction Steps

import boto3
from Moto import mock_aws   
   
    with mock_aws():
        s3 =  boto3.client("s3")
        s3.create_bucket(Bucket="my_bucket")
        s3.create_bucket(Bucket="my_bucket")

Possible Solution

Looking at the boto code it seems the check in create bucket should be:

def create_bucket(self, bucket_name: str, region_name: str) -> FakeBucket:
        if bucket_name in self.buckets:

Instead of:

def create_bucket(self, bucket_name: str, region_name: str) -> FakeBucket:
        if bucket_name in s3_backends.bucket_accounts.keys():

Additional Information/Context

Screenshot 2024-09-19 at 10 29 15 Screenshot 2024-09-19 at 10 30 39 Screenshot 2024-09-19 at 10 30 18

Please see the preceding screenshots for more details.

You will see that list buckets queries the correct property but create bucket incorrectly queries a property with no buckets

SDK version used

5.0.14

Environment details (OS name and version, etc.)

Mac OS - 14.6.1. Python 3.9 (Anaconda env)

@ash-murphy-colibri ash-murphy-colibri added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Sep 19, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant