Because every field in AwsCredentials has a default or default factory, Pydantic considers non-matching credentials dictionaries valid and selects AwsCredentials when calling S3Bucket.parse_obj().
Example
from pydantic import BaseModel, Field
from typing import Union
from prefect_aws import AwsCredentials, MinIOCredentials
class S3Bucket(BaseModel):
bucket_name: str = Field(default=...)
credentials: Union[AwsCredentials, MinIOCredentials] = Field(default_factory=AwsCredentials)
if __name__=="__main__":
minio_bucket_parsed = S3Bucket.parse_obj({
"bucket_name": "my_bucket",
"credentials": {
"minio_root_user": "Kevin",
"minio_root_password": "password",
}
})
s3_bucket_parsed = S3Bucket.parse_obj({
"bucket_name": "my_bucket",
"credentials": {
"aws_access_key_id": "1234",
"aws_access_key_secret": "5678",
}
})
s3_bucket_no_creds_parsed = S3Bucket.parse_obj({
"bucket_name": "my_bucket"
})
print(type(minio_bucket_parsed.credentials))
print(type(s3_bucket_parsed.credentials))
print(type(s3_bucket_no_creds_parsed.credentials))
Closes #210
Because every field in
AwsCredentials
has a default or default factory, Pydantic considers non-matching credentials dictionaries valid and selectsAwsCredentials
when callingS3Bucket.parse_obj()
.Example
Reordered:
Screenshots
Checklist
pre-commit
checks.pre-commit install && pre-commit run --all
locally for formatting and linting.mkdocs serve
view documentation locally.