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
arbitrary_types_allowed
no longer works with root models in V2
#6710
Comments
@MarkusSintonen while I think ideally this wouldn't error, I think it might be hard to get it to work properly, since it's erroring while trying to create from typing import Any
import numpy
from pydantic import ConfigDict, RootModel
class MyNdarray(RootModel[Any]):
root: numpy.ndarray
model_config = ConfigDict(arbitrary_types_allowed=True)
# defines deserialization of list to ndarray etc... I was worried this might not give the right mypy behavior, but I wasn't able to produce any typing issues using the above, as far as I could tell it behaved the way you'd want it to (same as I'd be open to PRs fixing it for Open to debate/other ideas |
@dmontagu I think that both forms should work identical in general despite what type is being used for class MyNdarray(RootModel[numpy.ndarray]):
model_config = ConfigDict(arbitrary_types_allowed=True) and class MyNdarray(RootModel):
root = numpy.ndarray
model_config = ConfigDict(arbitrary_types_allowed=True) I agree that I will focus in this issue just on making |
After thorough review of this issue I'm tempting to call this known behavior and add a note regarding this to the docs. The issue here is that class Model(RootModel):
root: numpy.ndarray and Model = RootModel[numpy.ndarray] When creating a This means that in the code below we are attempting to create a class MyNdarray(RootModel[numpy.ndarray]):
model_config = ConfigDict(arbitrary_types_allowed=True) |
Initial Checks
Description
In V2 root models
arbitrary_types_allowed
no longer works. In V1 it used to work. Is it intended not to work anymore? Example below showing an use case that used to work in V1. I guess the issue is somehow related to generic models handling in V2.Example Code
Python, Pydantic & OS Version
Selected Assignee: @lig
The text was updated successfully, but these errors were encountered: