From d995f0e55c9bc447fdbb53cf1a47324bd411a940 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Thu, 12 Dec 2024 09:55:50 +0200 Subject: [PATCH] fix(main.py): Fix linter error Signed-off-by: Denys Fedoryshchenko --- api/main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/api/main.py b/api/main.py index a649a68b..8d6c2d63 100644 --- a/api/main.py +++ b/api/main.py @@ -34,6 +34,7 @@ from pymongo.errors import DuplicateKeyError from fastapi_users import FastAPIUsers from beanie import PydanticObjectId +from pydantic import BaseModel from kernelci.api.models import ( Node, Hierarchy, @@ -42,7 +43,6 @@ KernelVersion, EventHistory, ) -from pydantic import BaseModel from .auth import Authentication from .db import Database from .pubsub import PubSub @@ -62,7 +62,6 @@ from .metrics import Metrics - @asynccontextmanager async def lifespan(app: FastAPI): # pylint: disable=redefined-outer-name """Lifespan functions for startup and shutdown events""" @@ -714,6 +713,17 @@ async def post_node(node: Node, return obj +def is_same_flags(old_node, new_node): + """ Compare processed_by_kcidb_bridge flags + Returns True if flags are same, False otherwise + """ + old_flag = old_node.processed_by_kcidb_bridge + new_flag = new_node.processed_by_kcidb_bridge + if old_flag == new_flag: + return True + return False + + @app.put('/node/{node_id}', response_model=Node, response_model_by_alias=False) async def put_node(node_id: str, node: Node, user: str = Depends(authorize_user), @@ -757,9 +767,7 @@ async def put_node(node_id: str, node: Node, # KCIDB flags are reset on any update, because this means we need # to reprocess updated node. # So reset flag, unless flag is changed in the request - old_flag = node_from_id.processed_by_kcidb_bridge - new_flag = node.processed_by_kcidb_bridge - if old_flag == new_flag: + if is_same_flags(node_from_id, node): new_node_def.processed_by_kcidb_bridge = False # Update node in the DB