Hey everyone - attempting to use a SecretStr field...
# ask-community
s
Hey everyone - attempting to use a SecretStr field in block document raises a pydantic validation error ( no validator found for <class 'pydantic.types.SecretStr'>, see
arbitrary_types_allowed
in Config). Does 'arbitrary_types_allowed' need to be configured?
1
🙏 1
a
Can you try importing SecretStr from pydantic.v1?
s
yep yep - that works. Thanks!
🙌 1
a
Importing from pydantic itself should be supported in the next major version. Just one of those idiosyncrasies while we transition major pydantic versions in earnest
s
yep - makes perfect sense - I appreciate it, I would have spent hours tracing that down!
k
Hey Adam, is this still the recommended approach? for now?
a
yep!
k
Any inkling into what's going on here? from...
Copy code
secret_block = Secret(value=SecretStr('secret'))
secret_block.save(name='test', overwrite=True)
Copy code
File "<ipython-input-11-14fcf4c2faa1>", line 26, in save
    secret_block = Secret(value=SecretStr(self.secret))
  File "/Users/kevingould/.pyenv/versions/3.10.9/envs/ssm-data-pipeline/lib/python3.10/site-packages/prefect/blocks/core.py", line 265, in __init__
    super().__init__(*args, **kwargs)
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Secret
value
  str type expected (type=type_error.str)
a
I think that value still expects the actual string ‘secret’. You don’t need to wrap ‘secret’ as
SecretStr('secret')
1