Repository: kserve/kserve

Issue:
Pydantic ValidationError due to dropped InferRequest id
/kind bug

**What steps did you take and what happened:**
[A clear and concise description of what the bug is.]
I am using kserve as a wrapper around Torchserve, with the v2 Inference API. A pydantic validation error is thrown when parsing the returned InferenceResponse due to the created InferRequest dropping the id. The downstream torchserve inferene then receives a null id, and returns null id in its response too.

```
2023-05-25 14:39:33.490 16 uvicorn.error ERROR [run_asgi():376] Exception in ASGI application
Traceback (most recent call last):
  File "/opt/env/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/opt/env/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/fastapi/applications.py", line 270, in __call__
    await super().__call__(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/opt/env/lib/python3.9/site-packages/timing_asgi/middleware.py", line 68, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/opt/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/opt/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/opt/env/lib/python3.9/site-packages/fastapi/routing.py", line 235, in app
    raw_response = await run_endpoint_function(
  File "/opt/env/lib/python3.9/site-packages/fastapi/routing.py", line 161, in run_endpoint_function
    return await dependant.call(**values)
  File "/opt/env/lib/python3.9/site-packages/kserve/protocol/rest/v2_endpoints.py", line 135, in infer
    res = InferenceResponse.parse_obj(response)
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for InferenceResponse
id
  none is not an allowed value (type=type_error.none.not_allowed)
```

I will create a simple PR to fix this.

**What did you expect to happen:**
Inference to succeed, with id passed through.


**What's the InferenceService yaml:**
[To help us debug please run `kubectl get isvc $name -n $namespace -oyaml` and paste the output]
Not applicable. Testing with docker.

**Anything else you would like to add:**
[Miscellaneous information that will assist in solving the issue.]
Not applicable.



Discussion:

Resolving patch:
diff --git a/python/kserve/kserve/protocol/rest/v2_endpoints.py b/python/kserve/kserve/protocol/rest/v2_endpoints.py
--- a/python/kserve/kserve/protocol/rest/v2_endpoints.py
+++ b/python/kserve/kserve/protocol/rest/v2_endpoints.py
@@ -133,7 +133,7 @@ async def infer(
                                    data=input.data,
                                    parameters={} if input.parameters is None else input.parameters
                                    ) for input in request_body.inputs]
-        infer_request = InferRequest(model_name=model_name, infer_inputs=infer_inputs,
+        infer_request = InferRequest(request_id=request_body.id, model_name=model_name, infer_inputs=infer_inputs,
                                      parameters=request_body.parameters)
         response, response_headers = await self.dataplane.infer(model_name=model_name,
                                                                 request=infer_request,


Test patch: