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

Problem with "before" model_validators #8

Open
daniel-thom opened this issue Apr 2, 2024 · 1 comment
Open

Problem with "before" model_validators #8

daniel-thom opened this issue Apr 2, 2024 · 1 comment

Comments

@daniel-thom
Copy link

Functions like this one are causing us an issue. We are constructing Line from an already-constructed Line_Common instance. The code fails because it expects a dict instead.

I think that the best solution is to make them mode="after" validators instead. I have found it to always be better to use after validators unless I really need to perform some manipulation before Pydantic has run its type conversions. If this function were an after validator then it self would always be a constructed model.

Would you be OK with such a change? We could submit a PR.

@PMeira
Copy link
Member

PMeira commented Apr 10, 2024

Originally it was done with mode="after" and _fields_set = self.model_fields_set, but there was something from Pydantic that was breaking the logic. It could have been how defaults are handled, so we'd get back to #7.

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