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

Fix HttpToS3Operator throws exception if s3_bucket parameter is not passed #43828

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions providers/src/airflow/providers/amazon/aws/hooks/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def provide_bucket_name(func: Callable) -> Callable:
async def maybe_add_bucket_name(*args, **kwargs):
bound_args = function_signature.bind(*args, **kwargs)

if "bucket_name" not in bound_args.arguments:
if not bound_args.arguments.get("bucket_name"):
self = args[0]
if self.aws_conn_id:
connection = await sync_to_async(self.get_connection)(self.aws_conn_id)
Expand Down Expand Up @@ -116,7 +116,7 @@ async def wrapper(*args: Any, **kwargs: Any) -> Any:
def wrapper(*args, **kwargs) -> Callable:
bound_args = function_signature.bind(*args, **kwargs)

if "bucket_name" not in bound_args.arguments:
if not bound_args.arguments.get("bucket_name"):
self = args[0]

if "bucket_name" in self.service_config:
Expand Down
6 changes: 6 additions & 0 deletions providers/tests/amazon/aws/hooks/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,12 @@ def test_function(self, bucket_name=None):
test_bucket_name = fake_s3_hook.test_function(bucket_name="bucket")
assert test_bucket_name == "bucket"

# Test: `bucket_name` should use the explicitly provided value over `service_config`
test_bucket_name = fake_s3_hook.test_function(bucket_name="some_custom_bucket")
assert (
test_bucket_name == "some_custom_bucket"
), "Expected provided bucket_name to take precedence over fallback"

def test_delete_objects_key_does_not_exist(self, s3_bucket):
# The behaviour of delete changed in recent version of s3 mock libraries.
# It will succeed idempotently
Expand Down