jina-ai / jina

☁️ Build multimodal AI applications with cloud-native stack
https://docs.jina.ai
Apache License 2.0
20.54k stars 2.21k forks source link

float being checked as a list #6154

Closed nick-konovalchuk closed 3 months ago

nick-konovalchuk commented 3 months ago

Describe the bug I'm trying to use a doc with a float field. Sending a request via Swagger page. Pydantic does list checks for the float field

from jina import Executor, Flow, requests

from docarray import BaseDoc, DocList

class FloatDoc(BaseDoc):
    num: float

class Executor1(Executor):
    @requests
    def foo(self, docs: DocList[BaseDoc], **kwargs) -> DocList[FloatDoc]:
        return DocList[FloatDoc]([FloatDoc(num=0.3)])

f = Flow(protocol="HTTP", port=5555).add(uses=Executor1)
with f:
    f.block()

geting

  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for FloatDoc
num
  value is not a valid list (type=type_error.list)

This issue only happens when deployed with jina. Regular method work fine

from docarray import BaseDoc, DocList

from main import Executor1

ex = Executor1()
docs = DocList[BaseDoc]([BaseDoc()])

out = ex.foo(docs)

print(out[0])

Describe how you solve it


Environment

Screenshots

nick-konovalchuk commented 3 months ago

This might be related https://github.com/jina-ai/jina/issues/6030

JoanFM commented 3 months ago

This is indeed strange, I will take a look

JoanFM commented 3 months ago

This is the underlying cause of the issue:

from docarray import BaseDoc

class DummyDoc(BaseDoc):
    number: float

from jina.serve.runtimes.helper import _create_aux_model_doc_list_to_list, _create_pydantic_model_from_schema

model = _create_pydantic_model_from_schema(model_name='DummyDoc2',
                                           schema=_create_aux_model_doc_list_to_list(DummyDoc).schema(),
                                           cached_models={})
model(number=0.5)

This fails.