From 102984348880068e5a4941c3e2cf61a7a91c448c Mon Sep 17 00:00:00 2001 From: Joan Martinez Date: Tue, 17 Dec 2024 18:18:54 +0100 Subject: [PATCH] feat: change return error code --- .github/workflows/cd.yml | 47 ++++++------ .github/workflows/ci.yml | 75 +++++++++---------- .../gateway/http_fastapi_app_docarrayv2.py | 4 +- jina/serve/runtimes/worker/http_csp_app.py | 4 +- .../serve/runtimes/worker/http_fastapi_app.py | 4 +- .../serve/runtimes/worker/request_handling.py | 3 +- 6 files changed, 65 insertions(+), 72 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 805582199bfb3..3b26af7155829 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -281,9 +281,6 @@ jobs: matrix: include: # linux - - os: ubuntu-latest - python: '3.7' - python-manylinux-tag: "cp37-cp37m" - os: ubuntu-latest python: '3.8' python-manylinux-tag: "cp38-cp38" @@ -451,7 +448,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.10] test-path: ${{fromJson(needs.prep-testbed.outputs.matrix)}} steps: - uses: actions/checkout@v2.5.0 @@ -503,7 +500,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -587,10 +584,10 @@ jobs: # with: # access_token: ${{ github.token }} - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Test hubapp with hubpods run: | ./tests/jinahub/test_integration.sh @@ -604,10 +601,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -634,7 +631,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -646,10 +643,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -676,7 +673,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -688,10 +685,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -718,7 +715,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -730,10 +727,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -761,7 +758,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -773,10 +770,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -801,7 +798,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -813,10 +810,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -839,7 +836,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be1a07813463d..886cf930a0352 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,10 +23,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Lint with flake8 run: | pip install flake8 @@ -41,10 +41,10 @@ jobs: - uses: actions/checkout@v2.5.0 with: fetch-depth: 0 - - name: Set up Python 3.8 - uses: actions/setup-python@v1 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.10 - id: file_changes uses: Ana06/get-changed-files@v1.2 - name: docstring check with darglint and pydocstyle @@ -58,10 +58,10 @@ jobs: - uses: actions/checkout@v2.5.0 with: fetch-depth: 0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - id: file_changes uses: Ana06/get-changed-files@v1.2 - name: check black @@ -77,11 +77,11 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} ref: ${{ github.event.pull_request.head.sha }} - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 if: ${{ !github.event.pull_request.head.repo.fork }} with: - python-version: 3.8 + python-version: 3.10 - name: Styling id: styling if: ${{ !github.event.pull_request.head.repo.fork }} @@ -158,10 +158,10 @@ jobs: # with: # access_token: ${{ github.token }} - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Test hubapp with hubpods run: | ./tests/jinahub/test_integration.sh @@ -175,10 +175,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -205,7 +205,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -217,10 +217,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -247,7 +247,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -259,10 +259,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -289,7 +289,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -301,7 +301,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: python-version: 3.8 @@ -332,7 +332,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -344,10 +344,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -372,7 +372,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -385,10 +385,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip . @@ -411,7 +411,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -439,7 +439,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.10] protobuf-version: ['==3.19.6', ''] steps: - uses: actions/checkout@v2.5.0 @@ -499,7 +499,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -515,7 +515,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.10] protobuf-version: ['==3.19.6', ''] steps: - uses: actions/checkout@v2.5.0 @@ -568,7 +568,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -584,9 +584,6 @@ jobs: matrix: include: # linux - - os: ubuntu-latest - python: '3.7' - python-manylinux-tag: "cp37-cp37m" - os: ubuntu-latest python: '3.8' python-manylinux-tag: "cp38-cp38" @@ -703,7 +700,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.10] test-path: ${{fromJson(needs.prep-testbed.outputs.matrix)}} steps: - uses: actions/checkout@v2.5.0 @@ -757,7 +754,7 @@ jobs: files: "coverage.xml" - name: Upload coverage from test to Codecov uses: codecov/codecov-action@v3.1.1 - if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8' + if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.10' with: file: coverage.xml name: ${{ matrix.test-path }}-codecov @@ -802,10 +799,10 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v2.5.0 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.10 - name: Prepare enviroment run: | python -m pip install --upgrade pip diff --git a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py index 76e3c429da7b9..9939ced58acf0 100644 --- a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py +++ b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py @@ -41,7 +41,7 @@ def get_fastapi_app( if expose_graphql_endpoint: logger.error(f' GraphQL endpoint is not enabled when using docarray >0.30') with ImportExtensions(required=True): - from fastapi import FastAPI, Response, HTTPException + from fastapi import FastAPI, Response, HTTPException, status as http_status from fastapi.middleware.cors import CORSMiddleware import pydantic from pydantic import Field @@ -216,7 +216,7 @@ async def post(body: input_model, response: Response): status = resp.header.status if status.code == jina_pb2.StatusProto.ERROR: - raise HTTPException(status_code=499, detail=status.description) + raise HTTPException(status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR, detail=status.description) else: result_dict = resp.to_dict() return result_dict diff --git a/jina/serve/runtimes/worker/http_csp_app.py b/jina/serve/runtimes/worker/http_csp_app.py index a670a0d1d932c..442241f416f07 100644 --- a/jina/serve/runtimes/worker/http_csp_app.py +++ b/jina/serve/runtimes/worker/http_csp_app.py @@ -30,7 +30,7 @@ def get_fastapi_app( """ with ImportExtensions(required=True): import pydantic - from fastapi import FastAPI, HTTPException, Request + from fastapi import FastAPI, HTTPException, Request, status as http_status from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel, Field from pydantic.config import BaseConfig, inherit_config @@ -131,7 +131,7 @@ async def process(body) -> output_model: status = resp.header.status if status.code == jina_pb2.StatusProto.ERROR: - raise HTTPException(status_code=499, detail=status.description) + raise HTTPException(status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR, detail=status.description) else: return output_model(data=resp.docs, parameters=resp.parameters) diff --git a/jina/serve/runtimes/worker/http_fastapi_app.py b/jina/serve/runtimes/worker/http_fastapi_app.py index 889166d8aeb63..edb4c9dba7afa 100644 --- a/jina/serve/runtimes/worker/http_fastapi_app.py +++ b/jina/serve/runtimes/worker/http_fastapi_app.py @@ -33,7 +33,7 @@ def get_fastapi_app( :return: fastapi app """ with ImportExtensions(required=True): - from fastapi import FastAPI, Response, HTTPException + from fastapi import FastAPI, Response, HTTPException, status as http_status import pydantic from fastapi.middleware.cors import CORSMiddleware import os @@ -116,7 +116,7 @@ async def post(body: input_model, response: Response): status = resp.header.status if status.code == jina_pb2.StatusProto.ERROR: - raise HTTPException(status_code=499, detail=status.description) + raise HTTPException(status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR, detail=status.description) else: if not docarray_v2: docs_response = resp.docs.to_dict() diff --git a/jina/serve/runtimes/worker/request_handling.py b/jina/serve/runtimes/worker/request_handling.py index 450690d33bcdc..97d90fa954372 100644 --- a/jina/serve/runtimes/worker/request_handling.py +++ b/jina/serve/runtimes/worker/request_handling.py @@ -1079,7 +1079,6 @@ def _extract_tracing_context( ) -> Optional['Context']: if self.tracer: from opentelemetry.propagate import extract - context = extract(dict(metadata)) return context @@ -1116,7 +1115,7 @@ async def process_data( if is_generator: result = await self.handle_generator( - requests=requests,tracing_context=tracing_context + requests=requests, tracing_context=tracing_context ) else: result = await self.handle(