Skip to content

fix: fix nested doc to json#1502

Merged
samsja merged 2 commits intomainfrom
fix-json-nested
May 8, 2023
Merged

fix: fix nested doc to json#1502
samsja merged 2 commits intomainfrom
fix-json-nested

Conversation

@samsja
Copy link
Copy Markdown
Member

@samsja samsja commented May 8, 2023

Context

this pr is fixing : #1501

it allow to do

from docarray import DocVec, BaseDoc, DocList
from docarray.documents.image import ImageDoc

class Request(BaseDoc):
    images: DocList[ImageDoc]
        
images = DocList[ImageDoc]([ImageDoc(url=f'http://url.com/{i}.png') for i in range(10)])
request = Request(images=images)
request.json()

without having an error

what this pr exactly do:

  • when calling json it manually deal with the nested DocList, otherwise Pydantic does some weird logic because it think it is a List (which is it)
  • Custom validation on DocList. Now if the input is not a DocList but a list of dict lets say, it will try to validate every member of the iterable with the doc_type and then create a DocList out of it

Signed-off-by: samsja <[email protected]>
@samsja samsja marked this pull request as ready for review May 8, 2023 08:52
@github-actions
Copy link
Copy Markdown

github-actions bot commented May 8, 2023

📝 Docs are deployed on https://ft-fix-json-nested--jina-docs.netlify.app 🎉

@samsja samsja merged commit 67c7e6d into main May 8, 2023
@samsja samsja deleted the fix-json-nested branch May 8, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible Regression: ValueError when creating Request object with DocList of ImageDocs

3 participants