Skip to content

Commit

Permalink
fix: fail fast when no valid schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Jul 12, 2023
1 parent fb0b0c0 commit 5d1f6d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jina/serve/executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def get_function_with_schema(fn: Callable) -> T:
else:
request_schema = docs_annotation or DocumentArray[LegacyDocument]
response_schema = return_annotation or DocumentArray[LegacyDocument]
from docarray import DocList
if not issubclass(request_schema, DocList) or not issubclass(response_schema, DocList):
faulty_schema = 'request_schema' if not issubclass(request_schema, DocList) else 'response_schema'
raise Exception(f'The {faulty_schema} schema for {fn.__name__}: {request_schema} is not a DocList. Please make sure that your endpoints used DocList for request and response schema')

return _FunctionWithSchema(fn, request_schema, response_schema)

Expand Down
17 changes: 17 additions & 0 deletions tests/integration/docarray_v2/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,23 @@ def foo(self, docs: DocList[ImageDoc], **kwargs) -> DocList[ImageDoc]:
pass


@pytest.mark.parametrize('ctxt_manager', ['deployment', 'flow'])
def test_wrong_schemas(ctxt_manager):
class MyExec(Executor):
@requests
def foo(self, docs: TextDoc, **kwargs) -> DocList[TextDoc]:
pass

if ctxt_manager == 'flow':
ctxt_mgr = Flow().add(uses=MyExec)
else:
ctxt_mgr = Deployment(uses=MyExec)

with pytest.raises(RuntimeFailToStart):
with ctxt_mgr:
pass


@pytest.mark.parametrize('protocol', ['grpc', 'http', 'websocket'])
def test_flow_incompatible_bifurcation(protocol):
class First(Executor):
Expand Down

0 comments on commit 5d1f6d6

Please sign in to comment.