Skip to content

Commit d995f0e

Browse files
committed
fix(main.py): Fix linter error
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent dc5134e commit d995f0e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

api/main.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from pymongo.errors import DuplicateKeyError
3535
from fastapi_users import FastAPIUsers
3636
from beanie import PydanticObjectId
37+
from pydantic import BaseModel
3738
from kernelci.api.models import (
3839
Node,
3940
Hierarchy,
@@ -42,7 +43,6 @@
4243
KernelVersion,
4344
EventHistory,
4445
)
45-
from pydantic import BaseModel
4646
from .auth import Authentication
4747
from .db import Database
4848
from .pubsub import PubSub
@@ -62,7 +62,6 @@
6262
from .metrics import Metrics
6363

6464

65-
6665
@asynccontextmanager
6766
async def lifespan(app: FastAPI): # pylint: disable=redefined-outer-name
6867
"""Lifespan functions for startup and shutdown events"""
@@ -714,6 +713,17 @@ async def post_node(node: Node,
714713
return obj
715714

716715

716+
def is_same_flags(old_node, new_node):
717+
""" Compare processed_by_kcidb_bridge flags
718+
Returns True if flags are same, False otherwise
719+
"""
720+
old_flag = old_node.processed_by_kcidb_bridge
721+
new_flag = new_node.processed_by_kcidb_bridge
722+
if old_flag == new_flag:
723+
return True
724+
return False
725+
726+
717727
@app.put('/node/{node_id}', response_model=Node, response_model_by_alias=False)
718728
async def put_node(node_id: str, node: Node,
719729
user: str = Depends(authorize_user),
@@ -757,9 +767,7 @@ async def put_node(node_id: str, node: Node,
757767
# KCIDB flags are reset on any update, because this means we need
758768
# to reprocess updated node.
759769
# So reset flag, unless flag is changed in the request
760-
old_flag = node_from_id.processed_by_kcidb_bridge
761-
new_flag = node.processed_by_kcidb_bridge
762-
if old_flag == new_flag:
770+
if is_same_flags(node_from_id, node):
763771
new_node_def.processed_by_kcidb_bridge = False
764772

765773
# Update node in the DB

0 commit comments

Comments
 (0)