-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
protected_namespaces
isn't as useful as could be
#9177
Comments
Thanks for the well thought out feature request. I'm in favor of 3, bc as you mentioned, it's the most backwards compatible option. That being said, let's see what the team thinks before we move ahead with a PR. Will get back to you shorlty! |
I agree with @antoine-lizee that it's quite annoying when using it in a deep learning project. I think |
Changing everything to |
Yeah it makes sense. I think 3/ is the best short-term. Coming back to the Something like:
|
As an alternative (or additionally), why not make the One extra advantage is that this would allow calling |
Initial Checks
Description
Currently, we get 2 behaviours:
model_
will issue a warning. That's desirable in some cases but annoying in others, especially in the age of AI.Currently, setting
protected_namespaces=()
in the config removes both. (Note: it is not clear in the documentation that the error is silenced too)This is a problem because silencing the warning in the cases that are ok is now very dangerous (you also silence a useful error).
Potential suggestions:
protected_namespaces=()
. It seems that it was the initial behaviour some time ago, so my guess is that the changes have been made for a reason (probably the rare of cases when you want to override)pydantic_
will likely remove 99% of the issue. (see Prefix all protected namespaces with "pydantic_" #7031 too)It seems that 3/ is the most backward compatible option, but it adds one more config option...
What do you guys think?
( Side note: I'm also not sure of the point of
protected_namespaces
in general. What are good use cases for setting other protected namespaces? It seems that I can only reproduce the warning behaviour on other namespaces, which I also get when defining the model unless I set the config after the fields somehow )Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: