Skip to content

Commit a51a0e9

Browse files
author
Jeny Sadadia
committed
api.main: preserve model parsing and fix kver job
When submodel like `Checkout` or `Test` node is submitted, explicit validation takes place in `parse_node_obj` method. The method also converts request parameters to defined data types e.g. for storing kernel version, `version` and `patchlevel` fields will be converted to `int`. Losing all these conversion and storing object as it received will raise issues like `kver` job failure. In order to preserve type casting happened during validation in `parse_node_obj`, store it to `node`. If we try to store this node object directly, it will raise issue while JSON serialization of `Node.data` field in `_get_node_event_data`. Also, DB will not be able to map collection name from submodel type as the collection dictionary uses only one collection for all kind of nodes i.e. `node`. Fixing above issues will also fix `kver` job failure. Fixes: b785e19 ("api.main: use node endpoints for all type of Node subtypes") Signed-off-by: Jeny Sadadia <[email protected]>
1 parent b584875 commit a51a0e9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

api/main.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,11 @@ async def post_node(node: Node,
540540
current_user: User = Depends(get_current_user)):
541541
"""Create a new node"""
542542
# Explicit pydantic model validation
543-
parse_node_obj(node)
543+
parsed_node = parse_node_obj(node)
544+
# Convert again to parent model `Node` in order to enable JSON
545+
# serialization of nested models (such as `CheckoutData`) and
546+
# map model against existing DB collection i.e. `Node`
547+
node = Node(**parsed_node.dict())
544548

545549
# [TODO] Implement sanity checks depending on the node kind
546550
if node.parent:

0 commit comments

Comments
 (0)