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
Bug: Jsonschema of DocList not correct #1521
Comments
After digging into this for a while it seems like we have a bit of a problem. tl;dr: We cannot have working validation for longer version:
# in AnyDocArray.__class_getitem__
class _DocArrayTyped(cls): # type: ignore
doc_type: Type[BaseDoc] = cast(Type[BaseDoc], item)
__origin__: Type['AnyDocArray'] = cls # add this
__args__: Tuple[Any, ...] = (item,) # add this
class MyDoc(BaseDoc):
docs: DocList[ImageDoc]
d = MyDoc(docs=DocList[ImageDoc]([ImageDoc()]))
print(type(d.docs)) # this will be a `list` instead of `DocList[ImageDoc]` This error can be reproduced in "pure" pydantic, showing that it is not per se a docarray issue: T_item = TypeVar('T_item')
class MyOtherList(List[T_item], typing.Generic[T_item]):
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, value, field, config):
print('validating :)') # this is never called/printed
if isinstance(value, MyList):
print(f'{type(value)=}')
return value
raise TypeError(f'Cannot validate')
class OtherDoc(BaseModel):
docs: MyOtherList[int]
d = OtherDoc(docs=MyOtherList[int]([1, 2, 3]))
print(type(d.docs)) # this will be a list instead of MyList
Conclusion: The reason validation on |
So we wait for Pydantic v2 to fix this ? Or we can undo the list like things and try to fix it (I don't think we should do it ) |
I would wait |
We wait and document |
DocList
does not generate a correct JSONSchema; the schema of the documents in the doclist do not show up:This is the cause of OpenAPI through FastAPI not working properly, as seen in #1449
The text was updated successfully, but these errors were encountered: