Skip to content

Removal of s3 conn_type renders provide_bucket_name() useless #27587

@matthewblock

Description

@matthewblock

Apache Airflow Provider(s)

amazon

Versions of Apache Airflow Providers

apache-airflow-providers-amazon==6.0.0

Apache Airflow version

2.4.2

Operating System

debian buster

Deployment

Docker-Compose

Deployment details

No response

What happened

This PR 25980 removed s3 conn_type. The release notes for 6.0.0 indicate the user should instead use aws (Amazon Web Services) for conn_type:

In order to restore ability to test connection you need to change connection type from Amazon S3 (conn_type="s3") to Amazon Web Services (conn_type="aws") manually.

S3Hook, which assumed s3 conn_type, extensively uses a decorator provide_bucket_name():

def provide_bucket_name(func: T) -> T:
    """
    Function decorator that provides a bucket name taken from the connection
    in case no bucket name has been passed to the function.
    """
    function_signature = signature(func)

    @wraps(func)
    def wrapper(*args, **kwargs) -> T:
        bound_args = function_signature.bind(*args, **kwargs)

        if "bucket_name" not in bound_args.arguments:
            self = args[0]
            if self.aws_conn_id:
                connection = self.get_connection(self.aws_conn_id)
                if connection.schema:
                    bound_args.arguments["bucket_name"] = connection.schema

        return func(*bound_args.args, **bound_args.kwargs)

    return cast(T, wrapper)

The code for this decorator looks for the bucket_name in the connection object schema field. The Airflow connection UI had a text input for the schema field.

Now, the replacement aws conn_type connection UI only has text inputs for AWS Access Key ID, AWS Secret Access Key, and Extra.

If the user follows the recommendations of the provider docs and uses aws for conn_type, the decorator is rendered useless.

What you think should happen instead

Since the UI has no text input for schema a.k.a. bucket_name for deprecated s3 conn_type, either:

  1. The provide_bucket_name() decorator should instead get the bucket_name from extras, and the documentation should specify the path the user should use (something like s3.bucket_name)
  2. The decorator should be removed, and the user should be forced to explicitly enter the bucket_name as an arg for each of S3Hook's methods that require it.

How to reproduce

Try to create an Airflow connection of type aws (Amazon Web Services in UI) in the Airflow connections UI. Note that there is no field schema.

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions