ferruzzi commented on code in PR #35037:
URL: https://github.com/apache/airflow/pull/35037#discussion_r1364661974


##########
airflow/providers/amazon/aws/hooks/s3.py:
##########
@@ -912,14 +912,27 @@ def get_key(self, key: str, bucket_name: str | None = 
None) -> S3ResourceObject:
         :param bucket_name: the name of the bucket
         :return: the key object from the bucket
         """
+
+        def __sanitize_extra_args() -> dict[str, str]:
+            """Parse extra_args and return a dict with only the args listed in 
ALLOWED_DOWNLOAD_ARGS."""
+            return {
+                arg_name: arg_value
+                for (arg_name, arg_value) in self.extra_args.items()
+                if arg_name in S3Transfer(self.conn).ALLOWED_DOWNLOAD_ARGS
+            }
+
         s3_resource = self.get_session().resource(
             "s3",
             endpoint_url=self.conn_config.endpoint_url,
             config=self.config,
             verify=self.verify,
         )
         obj = s3_resource.Object(bucket_name, key)
-        obj.load()
+
+        # TODO inline this after debugging
+        new_args = __sanitize_extra_args()
+
+        obj.load(**new_args)

Review Comment:
   I am pretty sure it will work, and here's my reasoning.  I created a bucket 
named "ferruzzi-testing-123" and uploaded an empty text file named "hello.txt" 
via the console as the setup.  Then in a python console:
   
   ```python
   In [1]: import boto3
      ...: s3 = boto3.resource('s3')
      ...: obj = s3.Object("ferruzzi-testing-123", "hello.txt")
   
   In [2]: obj.content_type
   Out[2]: 'text/plain'
   
   In [3]: obj.load(content_type="text/plain")
   
   ```
   
   It fails gloriously and you get pages of stack traces, but the useful part 
is:
   
   ```
   ParamValidationError: Parameter validation failed:
   Unknown parameter in input: "content_type", must be one of: Bucket, IfMatch, 
IfModifiedSince, IfNoneMatch, IfUnmodifiedSince, Key, Range, VersionId, 
SSECustomerAlgorithm, SSECustomerKey, SSECustomerKeyMD5, RequestPayer, 
PartNumber, ExpectedBucketOwner, ChecksumMode
   ``` 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to