Skip to content

Commit

Permalink
fix(main.py): Fix linter error
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Dec 12, 2024
1 parent dc5134e commit d995f0e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (

Check failure on line 38 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
Expand All @@ -42,7 +43,6 @@
KernelVersion,
EventHistory,
)
from pydantic import BaseModel
from .auth import Authentication
from .db import Database
from .pubsub import PubSub
Expand All @@ -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"""
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d995f0e

Please sign in to comment.