Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate default value for Settings models #491

Open
ianmkenney opened this issue Feb 25, 2025 · 2 comments
Open

Validate default value for Settings models #491

ianmkenney opened this issue Feb 25, 2025 · 2 comments

Comments

@ianmkenney
Copy link
Member

The SettingsBaseModel, by default, only performs validation of fields directly fed to the constructor (see the configuration option, validate_all, in the link below). When model fields are not present, they are given a default value defined by the settings author. If the author fails to provide a default with the correct type, it will not be corrected, which can lead to inconsistencies downstream.

For example, if a GufeTokenizable has a field with a Settings object that doesn't adhere to its own schema, then the GufeKey reflects this inconsistency. Consider a scenario where a field's validator enforces a float, but an int was provided instead. If that GufeTokenizable is then translated to an intermediate format, such as a KeyedChain, the incorrectly typed integer value will also be translated. When converting the KeyedChain back into a GufeTokenizable, all models will be validated. The system will find an int for that field and cast it as a float. Although the recovered GufeTokenizable is now correctly validated, the GufeKey has changed between the original object and the new one, even though they functionally represent the same data.

Does it make sense to enforce this at the gufe level, or is watching out for this behavior the responsibility of the settings author?

https://docs.pydantic.dev/1.10/usage/model_config/

@mikemhenry
Copy link
Contributor

Knowing that we will be moving to pydantic 2 (someday?) do you know if the behavior changes at all? I think validate_all=True seems right for our use case.

@ianmkenney
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants