ai4os / DEEPaaS

A REST API to serve machine learning and deep learning models
https://deepaas.readthedocs.io
Apache License 2.0
34 stars 14 forks source link

raise HTTPException in train function never changes status from 'running' #123

Open BorjaEst opened 9 months ago

BorjaEst commented 9 months ago

Description

Some raised exceptions in the train function, do not change the status of the training.

Steps to Reproduce

Consider the following api.py for the demo example:

from aiohttp.web import HTTPException

def get_metadata():
    return {"status": "All ok"}

def get_train_args():
    return {}

def train(**kwargs):
    raise HTTPException(reason="Some error")

After calling:

curl -X 'POST' \
  'http://127.0.0.1:5000/v2/models/demo_app/train/' \
  -H 'accept: application/json' \
  -d ''

The server replies:

{
  "date": "2023-10-01 10:02:05.370140",
  "args": {},
  "uuid": "2631a11696c44cfea4a16d7095c64205",
  "status": "running"
}

However, after calling GET:

curl -X 'GET' \
  'http://127.0.0.1:5000/v2/models/demo_app/train/' \
  -H 'accept: application/json'

returns:

[
  {
    "date": "2023-10-01 10:02:05.370140",
    "args": {},
    "uuid": "2631a11696c44cfea4a16d7095c64205",
    "status": "running"
  }
]

Which is clearly not possible that status is running as an exception was raised.

Expected behavior:

It should be described http exceptions cannot be used in the documentation. There should be some protection mechanisms to avoid the usage of this exceptions. At worse, the GET method train should return:

[
  {
    "date": "2023-10-01 10:06:58.097097",
    "args": {},
    "uuid": "0fd0d21a8457482d885ee50d5aeed364",
    "status": "error",
    "message": "Some error"
  }
]

Ideally, the POST method train should return:

500 Internal Server Error

Versions

$ pip show deepaas
Name: deepaas
Version: 2.2.0
....
Location: /home/borja/miniconda3/envs/demo/lib/python3.10/site-packages
Requires: aiohttp, aiohttp-apispec, jsonschema, marshmallow, oslo.config, oslo.log, pbr, six, stevedore, typer, webargs, werkzeug
Required-by: demo-app