Skip to content

Commit

Permalink
api.main: fix validation error for None response
Browse files Browse the repository at this point in the history
FastAPI doesn't validate `None` when handler has specified
a response model. Fix the below validation error for GET node by ID
and GET group by ID requests:
```
{"detail":"1 validation error for UserGroup\nresponse\n  none
is not an allowed value (type=type_error.none.not_allowed)"}
```
The change has been effective from `fastapi 0.80.0` version.
Reference: tiangolo/fastapi#2725.

Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
  • Loading branch information
Jeny Sadadia committed Mar 22, 2024
1 parent 8f998e8 commit 86ae579
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/main.py
Expand Up @@ -10,7 +10,7 @@

import os
import re
from typing import List
from typing import List, Union
from fastapi import (
Depends,
FastAPI,
Expand Down Expand Up @@ -387,7 +387,7 @@ async def get_user_groups(request: Request):
return paginated_resp


@app.get('/group/{group_id}', response_model=UserGroup,
@app.get('/group/{group_id}', response_model=Union[UserGroup, None],
response_model_by_alias=False)
async def get_group(group_id: str):
"""Get user group information from the provided group id"""
Expand Down Expand Up @@ -448,7 +448,7 @@ async def translate_null_query_params(query_params: dict):
return translated


@app.get('/node/{node_id}', response_model=Node,
@app.get('/node/{node_id}', response_model=Union[Node, None],
response_model_by_alias=False)
async def get_node(node_id: str):
"""Get node information from the provided node id"""
Expand Down

0 comments on commit 86ae579

Please sign in to comment.