jina-ai/jina

float being checked as a list

nick-konovalchuk opened this issue · 3 comments

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

  • jina 3.24.0
  • docarray 0.40.0
  • jcloud 0.3
  • jina-hubble-sdk 0.39.0
  • jina-proto 0.1.27
  • protobuf 4.25.3
  • proto-backend upb
  • grpcio 1.57.0
  • pyyaml 6.0.1
  • python 3.10.13
  • platform Linux
  • platform-release 5.15.0-100-generic
  • platform-version #110~20.04.1-Ubuntu SMP Tue Feb 13 14:25:03 UTC 2024
  • architecture x86_64
  • processor x86_64
  • uid 252759714012098
  • session-id ead8c71d-e4d7-11ee-bbef-e5e234f79bc2
  • uptime 2024-03-18T06:30:50.153278
  • ci-vendor (unset)
  • internal False
  • JINA_DEFAULT_HOST (unset)
  • JINA_DEFAULT_TIMEOUT_CTRL (unset)
  • JINA_DEPLOYMENT_NAME (unset)
  • JINA_DISABLE_UVLOOP (unset)
  • JINA_EARLY_STOP (unset)
  • JINA_FULL_CLI (unset)
  • JINA_GATEWAY_IMAGE (unset)
  • JINA_GRPC_RECV_BYTES (unset)
  • JINA_GRPC_SEND_BYTES (unset)
  • JINA_HUB_NO_IMAGE_REBUILD (unset)
  • JINA_LOG_CONFIG (unset)
  • JINA_LOG_LEVEL (unset)
  • JINA_LOG_NO_COLOR (unset)
  • JINA_MP_START_METHOD (unset)
  • JINA_OPTOUT_TELEMETRY (unset)
  • JINA_RANDOM_PORT_MAX (unset)
  • JINA_RANDOM_PORT_MIN (unset)
  • JINA_LOCKS_ROOT (unset)
  • JINA_K8S_ACCESS_MODES (unset)
  • JINA_K8S_STORAGE_CLASS_NAME (unset)
  • JINA_K8S_STORAGE_CAPACITY (unset)
  • JINA_STREAMER_ARGS (unset)

Screenshots

This might be related
#6030

This is indeed strange, I will take a look

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.