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): Improve bulk-set robustness #585

Merged
merged 1 commit into from
Dec 5, 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
7 changes: 2 additions & 5 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 @@ -59,7 +59,7 @@
UserGroup,
)
from .metrics import Metrics
from pydantic import BaseModel

Check warning on line 62 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

third party import "from pydantic import BaseModel" should be placed before "from .auth import Authentication"


@asynccontextmanager
Expand Down Expand Up @@ -714,7 +714,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 717 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 @@ -772,7 +772,7 @@
return obj


class NodeUpdateRequest(BaseModel):

Check warning on line 775 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Missing class docstring
nodes: List[str]
field: str
value: str
Expand All @@ -797,18 +797,15 @@
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Node not found with id: {node_id}"
)
# verify ownership
# verify ownership, and ignore if not owner
if not user.username == node_from_id.owner:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Unauthorized to complete the operation"
)
continue
# 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':

Check warning on line 806 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Consider merging these comparisons with "in" to "value in ('true', 'True')"
value = True
elif value == 'false' or value == 'False':

Check warning on line 808 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Consider merging these comparisons with "in" to "value in ('false', 'False')"
value = False
setattr(node_from_id, field, value)
await db.update(node_from_id)
Expand Down
Loading