You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to nest a model with custom Union[str, Dict] root type in another model and seem to be getting some inconsistent behavior during model init. Consider following code snippet:
kwargs={'__root__': 'asdf'}
{'d': 'asdf'}
kwargs={'k': 'v'}
1 validation error for Model
d -> __root__
field required (type=value_error.missing)
kwargs={'__root__': {'k': 'v'}}
{'d': {'k': 'v'}}
In case of passing a string, it gets nested under the __root__ key automatically, which is not the case with the dict, which seems to require explicit nesting.
Is this expected?
The text was updated successfully, but these errors were encountered:
Thanks, @PrettyWood
I admit I find it somewhat confusing. From the discussions linked I gather that this custom root functionality is to be changed in the next major version. Do you happen to know what the scope of the changes is going to be and if this particular behavior is to be addressed somehow?
I'm afraid it won't be available anytime soon (see https://github.com/samuelcolvin/pydantic/milestone/2) @samuelcolvin is quite busy at the moment and the whole covid situation didn't help. Yet I agree we may need to put more effort on v2 (or at least give more visibility)
Question
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:Hello,
I'm trying to nest a model with custom
Union[str, Dict]
root type in another model and seem to be getting some inconsistent behavior during model init. Consider following code snippet:This outputs:
In case of passing a string, it gets nested under the
__root__
key automatically, which is not the case with the dict, which seems to require explicit nesting.Is this expected?
The text was updated successfully, but these errors were encountered: