Pydantic validation for the v1.2 API#53
Pydantic validation for the v1.2 API#53Yannicked wants to merge 13 commits intoiterorganization:developfrom
Conversation
deepakmaroo
left a comment
There was a problem hiding this comment.
There is exception when Dashboard request for list of simulations
127.0.0.1 - - [13/Mar/2026 09:50:27] "OPTIONS /v1.2/simulations?code.name=&status=&uploaded_by= HTTP/1.1" 200 -
Unhandled exception in SimulationList.get
Traceback (most recent call last):
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/src/simdb/remote/core/pydantic_utils.py", line 287, in wrapper
result = f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/src/simdb/remote/apis/v1_2/simulations.py", line 206, in get
return PaginatedResponse[SimulationListItem].model_validate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/venv/lib/python3.11/site-packages/pydantic/main.py", line 716, in model_validate
return cls.__pydantic_validator__.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for PaginatedResponse[SimulationListItem]
count
Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=110.66666666666667, input_type=float]
For further information visit https://errors.pydantic.dev/2.12/v/int_from_float
127.0.0.1 - - [13/Mar/2026 09:50:27] "GET /v1.2/simulations?code.name=&status=&uploaded_by= HTTP/1.1" 500 -
No sure if below error occurred due to local database migration applied
(venv) [marood@98dci4-srv-1002 SimDB_Test]$ simdb --debug remote sdcc list -l 10
Error: Corrupted data - non-optional metadata is None.
Traceback (most recent call last):
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/venv/bin/simdb", line 10, in <module>
sys.exit(main())
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/src/simdb/cli/remote_api.py", line 584, in list_simulations
return [Simulation.from_data(sim) for sim in data["results"]]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/src/simdb/cli/remote_api.py", line 584, in <listcomp>
return [Simulation.from_data(sim) for sim in data["results"]]
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/src/simdb/database/models/simulation.py", line 340, in from_data
metadata = checked_get(data, "metadata", list)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ITER/marood/Desktop/redhat-workspace/testing/SimDB_Test/src/simdb/database/models/utils.py", line 69, in checked_get
raise ValueError(f"Corrupted data - non-optional {key} is None.")
ValueError: Corrupted data - non-optional metadata is None.
Hi deepak, the first problem seems to be very odd. The count variable in the result seems to be ➜ ~ curl "http://localhost:5000/v1.2/simulations?code.name=&status=&uploaded_by=" -i
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 35680
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
Server: Werkzeug/2.0.3 Python/3.13.5
Date: Mon, 16 Mar 2026 14:44:20 GMT
{"count":1320,"page":1,"limit":100,"results":[{"uuid":{"_type":"uuid.U.....Is it possible to share the database you're using for me to debug with? |
|
Thank you @Yannicked for your comment, On second issue Error: Corrupted data - non-optional metadata is None. When requesting list of simulations list from local (applied database migration) database it complained error.
It seems in the local server is adding |
| return result | ||
|
|
||
|
|
||
| @api.route("/simulation/<path:sim_id>") |
There was a problem hiding this comment.
API call http://localhost:5000/v1.2/simulation/0eb5e8586c8d11f087edd4f5ef75e918 is failing with error message:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>TypeError: Object of type SimulationDataResponse is not JSON serializable // Werkzeug Debugger</title>
<link rel="stylesheet" href="?__debugger__=yes&cmd=resource&f=style.css"
type="text/css">
<!-- We need to make sure this has a favicon so that the debugger does
not accidentally trigger a request to /favicon.ico which might
change the application's state. -->
<link rel="shortcut icon"
href="?__debugger__=yes&cmd=resource&f=console.png">
<script src="?__debugger__=yes&cmd=resource&f=debugger.js"></script>
<script type="text/javascript">
var TRACEBACK = 139895977337424,
CONSOLE_MODE = false,
EVALEX = true,
EVALEX_TRUSTED = false,
SECRET = "t8CJKJPeke4iTJlQZOPo";
</script>
</head>
<body style="background-color: #fff">
<div class="debugger">
<h1>TypeError</h1>
<div class="detail">
<p class="errormsg">TypeError: Object of type SimulationDataResponse is not JSON serializable</p>
My local database is migrated with alembic_version: 22360ccb4154, does I missed upgrade or downgrade?
There was a problem hiding this comment.
I've pushed an update to address this, there was an issue with serializing numpy arrays in the metadata
I've added |
|
Current Dashboard expecting array data in |
Good catch, I'll implement the numpy ndarray type for now for compatibility with the current dashboard |
85dee87 to
f63c2de
Compare
This PR introduces a
@pydantic_validatedecorator that wires up typed request/response handling for all v1.2 API endpoints, replacing the previous mix of manualjsonify,try/except DatabaseError, and ad-hoc error returns.This also automatically adds the expected request and response data to the autogenerated swagger API docs:
