Skip to content

Commit 6ead077

Browse files
committed
Handle invalid S3 config options
1 parent f53d502 commit 6ead077

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

great_expectations/compatibility/aws.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def get_s3_boto3_options(boto3_options: Dict[str, Any]) -> Dict[str, Any]:
5858
return options
5959

6060
config = options.get("config")
61+
if config is not None and not isinstance(config, Config):
62+
return options
63+
6164
existing = getattr(config, "user_agent_extra", None) if config is not None else None
6265
user_agent_extra = f"{existing} {suffix}" if existing else suffix
6366

great_expectations/datasource/fluent/pandas_s3_datasource.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def _get_s3_client(self) -> BaseClient:
6868
"boto3_options", {}
6969
)
7070
try:
71-
s3_client = aws.boto3.client("s3", **aws.get_s3_boto3_options(boto3_options))
71+
s3_client = aws.boto3.client(
72+
"s3",
73+
**aws.get_s3_boto3_options(boto3_options),
74+
)
7275
except Exception as e:
7376
# Failure to create "s3_client" is most likely due invalid "boto3_options" dictionary. # noqa: E501 # FIXME CoP
7477
raise PandasS3DatasourceError( # noqa: TRY003 # FIXME CoP

great_expectations/datasource/fluent/spark_s3_datasource.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ def _get_s3_client(self) -> BaseClient:
7070
"boto3_options", {}
7171
)
7272
try:
73-
s3_client = aws.boto3.client("s3", **aws.get_s3_boto3_options(boto3_options))
73+
s3_client = aws.boto3.client(
74+
"s3",
75+
**aws.get_s3_boto3_options(boto3_options),
76+
)
7477
except Exception as e:
7578
# Failure to create "s3_client" is most likely due invalid "boto3_options" dictionary. # noqa: E501 # FIXME CoP
7679
raise SparkS3DatasourceError( # noqa: TRY003 # FIXME CoP

great_expectations/execution_engine/pandas_execution_engine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def _instantiate_azure_client(self) -> None:
167167
def _instantiate_s3_client(self) -> None:
168168
# If s3_client was passed in (from data source) use it, otherwise create our own
169169
self._s3 = self._config.get("s3_client") or aws.boto3.client(
170-
"s3", **aws.get_s3_boto3_options(self.config.get("boto3_options", {}))
170+
"s3",
171+
**aws.get_s3_boto3_options(self.config.get("boto3_options", {})),
171172
)
172173

173174
def _instantiate_gcs_client(self) -> None:

tests/compatibility/test_aws.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ def test_get_s3_boto3_options_appends_user_agent_and_preserves_options(
4141
)
4242
assert options["endpoint_url"] == "https://s3.example.com"
4343
assert boto3_options["config"] is config
44+
45+
46+
def test_get_s3_boto3_options_preserves_invalid_config() -> None:
47+
boto3_options: Dict[str, Any] = {
48+
"config": {"user_agent_extra": "invalid"},
49+
"endpoint_url": "https://s3.example.com",
50+
}
51+
52+
options = aws.get_s3_boto3_options(boto3_options)
53+
54+
assert options == boto3_options

0 commit comments

Comments
 (0)