Skip to content

Commit

Permalink
fix: fix inherit config
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Mar 7, 2024
1 parent ecdf2b6 commit 9000f65
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 8 additions & 2 deletions jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from jina.logging.logger import JinaLogger
from jina.serve.networking.sse import EventSourceResponse
from jina.types.request.data import DataRequest
from jina._docarray import is_pydantic_v2

Check warning on line 9 in jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py#L9

Added line #L9 was not covered by tests

if TYPE_CHECKING: # pragma: no cover
from opentelemetry import trace
Expand Down Expand Up @@ -80,7 +81,9 @@ async def _shutdown():
import os

from pydantic import BaseModel
from pydantic.config import BaseConfig, inherit_config
from pydantic.config import BaseConfig
if not is_pydantic_v2:
from pydantic.config import inherit_config

Check warning on line 86 in jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py#L84-L86

Added lines #L84 - L86 were not covered by tests

from jina.proto import jina_pb2
from jina.serve.runtimes.gateway.models import (
Expand Down Expand Up @@ -275,7 +278,10 @@ async def event_generator():
parameters_model = input_output_map['parameters'] or Optional[Dict]
default_parameters = ... if input_output_map['parameters'] else None

_config = inherit_config(InnerConfig, BaseDoc.__config__)
if not is_pydantic_v2:
_config = inherit_config(InnerConfig, BaseDoc.__config__)

Check warning on line 282 in jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py#L281-L282

Added lines #L281 - L282 were not covered by tests
else:
_config = InnerConfig

Check warning on line 284 in jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py#L284

Added line #L284 was not covered by tests

endpoint_input_model = pydantic.create_model(
f'{endpoint.strip("/")}_input_model',
Expand Down
11 changes: 8 additions & 3 deletions jina/serve/runtimes/worker/http_fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union

from jina import Document, DocumentArray
from jina._docarray import docarray_v2
from jina._docarray import docarray_v2, is_pydantic_v2

Check warning on line 5 in jina/serve/runtimes/worker/http_fastapi_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_fastapi_app.py#L5

Added line #L5 was not covered by tests
from jina.importer import ImportExtensions
from jina.serve.networking.sse import EventSourceResponse
from jina.types.request.data import DataRequest
Expand Down Expand Up @@ -38,7 +38,9 @@ def get_fastapi_app(
import os

from pydantic import BaseModel, Field
from pydantic.config import BaseConfig, inherit_config
from pydantic.config import BaseConfig
if not is_pydantic_v2:
from pydantic.config import inherit_config

Check warning on line 43 in jina/serve/runtimes/worker/http_fastapi_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_fastapi_app.py#L41-L43

Added lines #L41 - L43 were not covered by tests

from jina.proto import jina_pb2
from jina.serve.runtimes.gateway.models import _to_camel_case
Expand Down Expand Up @@ -168,7 +170,10 @@ async def streaming_get(request: Request = None, body: input_doc_model = None):
)

if docarray_v2:
_config = inherit_config(InnerConfig, BaseDoc.__config__)
if not is_pydantic_v2:
_config = inherit_config(InnerConfig, BaseDoc.__config__)

Check warning on line 174 in jina/serve/runtimes/worker/http_fastapi_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_fastapi_app.py#L173-L174

Added lines #L173 - L174 were not covered by tests
else:
_config = InnerConfig

Check warning on line 176 in jina/serve/runtimes/worker/http_fastapi_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_fastapi_app.py#L176

Added line #L176 was not covered by tests
else:
_config = input_doc_model.__config__

Expand Down
12 changes: 9 additions & 3 deletions jina/serve/runtimes/worker/http_sagemaker_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union

from jina._docarray import docarray_v2
from jina._docarray import docarray_v2, is_pydantic_v2

Check warning on line 3 in jina/serve/runtimes/worker/http_sagemaker_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_sagemaker_app.py#L3

Added line #L3 was not covered by tests
from jina.importer import ImportExtensions
from jina.types.request.data import DataRequest

Expand Down Expand Up @@ -33,7 +33,9 @@ def get_fastapi_app(
from fastapi import FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel, Field
from pydantic.config import BaseConfig, inherit_config
from pydantic.config import BaseConfig
if not is_pydantic_v2:
from pydantic.config import inherit_config

Check warning on line 38 in jina/serve/runtimes/worker/http_sagemaker_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_sagemaker_app.py#L36-L38

Added lines #L36 - L38 were not covered by tests

import os

Expand Down Expand Up @@ -235,7 +237,11 @@ def construct_model_from_line(
... if input_output_map['parameters']['model'] else None
)

_config = inherit_config(InnerConfig, BaseDoc.__config__)
if not is_pydantic_v2:
_config = inherit_config(InnerConfig, BaseDoc.__config__)

Check warning on line 241 in jina/serve/runtimes/worker/http_sagemaker_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_sagemaker_app.py#L240-L241

Added lines #L240 - L241 were not covered by tests
else:
_config = InnerConfig

Check warning on line 243 in jina/serve/runtimes/worker/http_sagemaker_app.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/worker/http_sagemaker_app.py#L243

Added line #L243 was not covered by tests

endpoint_input_model = pydantic.create_model(
f'{endpoint.strip("/")}_input_model',
data=(Union[List[input_doc_model], input_doc_model], ...),
Expand Down

0 comments on commit 9000f65

Please sign in to comment.