Could someone confirm if this is a bug, a bad usa...
# ask-community
w
Could someone confirm if this is a bug, a bad usage from my side, or indeed Prefect only works with pydantic v1 SecretStr? I'm trying to use Pydantic SecretStr (from v2) with prefect.filesystems.S3, but I'm receiving a validation error. Packages:
Copy code
>>> pip list | grep pydantic
pydantic                      2.6.1
pydantic_core                 2.16.2
pydantic-extra-types          2.5.0
pydantic-settings             2.1.0
>>> pip list | grep prefect 
prefect                       2.15.0
python 3.11.5
Copy code
from pydantic import SecretStr as SecretStrV2
from pydantic.v1 import SecretStr as SecretStrV1

from prefect.filesystems import S3

# Exception when using v2 
>>> S3(bucket_path="x", aws_access_key_id=SecretStrV2("abc"), aws_secret_access_key=SecretStrV2("abc"))

 File "/Users/user/.pyenv/versions/myenv/lib/python3.11/site-packages/prefect/blocks/core.py", line 265, in __init__
    super().__init__(*args, **kwargs)
  File "/Users/user/.pyenv/versions/myenv/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 2 validation errors for S3
aws_access_key_id
  str type expected (type=type_error.str)
aws_secret_access_key
  str type expected (type=type_error.str)

# With V1 works fine
>>> x = S3(bucket_path="x", aws_access_key_id=SecretStrV1("abc"), aws_secret_access_key=SecretStrV1("abc"))
>>> x.aws_access_key_id
SecretStr('**********')
a
from mobile, sorry if the answer is a little brief: Prefect objects are still v1 base models at heart. So whether you’re subclassing an object directly (or indirectly through the S3 function), pydantic doesn’t allow for that style of cross polination between v1 basemodels and v2 field types. This mismatch is regrettably intended behavior until our v1 deprecation window ends ~April.
n
+1 to what Adam said, and just to add some color the annoyance above mostly has to do with the fact that
S3
is
Block
subclass, which ultimately is a
type[V1BaseModel]
so because > pydantic doesn’t allow for that style of cross polination you cannot instantiate a v1 model that has a v1
SecretStr
field with a v2
SecretStr
instance
teamwork 1