Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(main.py): Reset kcidb flag on state change #586

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from pymongo.errors import DuplicateKeyError
from fastapi_users import FastAPIUsers
from beanie import PydanticObjectId
from kernelci.api.models import (

Check failure on line 37 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
PublishEvent,
Expand All @@ -42,6 +42,7 @@
KernelVersion,
EventHistory,
)
from pydantic import BaseModel
from .auth import Authentication
from .db import Database
from .pubsub import PubSub
Expand All @@ -59,10 +60,10 @@
UserGroup,
)
from .metrics import Metrics
from pydantic import BaseModel



@asynccontextmanager

Check warning on line 66 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

too many blank lines (3)
async def lifespan(app: FastAPI): # pylint: disable=redefined-outer-name
"""Lifespan functions for startup and shutdown events"""
await pubsub_startup()
Expand Down Expand Up @@ -714,7 +715,7 @@


@app.put('/node/{node_id}', response_model=Node, response_model_by_alias=False)
async def put_node(node_id: str, node: Node,

Check warning on line 718 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Too many local variables (16/15)
user: str = Depends(authorize_user),
noevent: Optional[bool] = Query(None)):
"""Update an already added node"""
Expand Down Expand Up @@ -747,6 +748,11 @@
status_code=status.HTTP_400_BAD_REQUEST,
detail=message
)
# if state changes, reset processed_by_kcidb_bridge flag
if node.state != new_node_def.state:
new_node_def.processed_by_kcidb_bridge = False
# Now we can update the state
new_node_def.state = node.state

# KCIDB flags are reset on any update, because this means we need
# to reprocess updated node.
Expand All @@ -756,9 +762,6 @@
if old_flag == new_flag:
new_node_def.processed_by_kcidb_bridge = False

# Now we can update the state
new_node_def.state = node.state

# Update node in the DB
obj = await db.update(new_node_def)
data = _get_node_event_data('updated', obj)
Expand All @@ -773,6 +776,7 @@


class NodeUpdateRequest(BaseModel):
"""Request model for updating multiple nodes"""
nodes: List[str]
field: str
value: str
Expand Down Expand Up @@ -803,9 +807,9 @@
# right now we support only field:
# processed_by_kcidb_bridge, also value should be boolean
if field == 'processed_by_kcidb_bridge':
if value == 'true' or value == 'True':
if value in ['true', 'True']:
value = True
elif value == 'false' or value == 'False':
elif value in ['false', 'False']:
value = False
setattr(node_from_id, field, value)
await db.update(node_from_id)
Expand Down
Loading