fixed bug in the database when assigning a state to a top file

This commit is contained in:
Linus Vogel 2026-05-14 20:31:25 +02:00
parent ec89c3b7ac
commit 42a748c6b6

View File

@ -1,6 +1,6 @@
import uuid
from sqlalchemy import select, delete, and_, bindparam
from sqlalchemy import select, delete, and_, or_, bindparam
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.orm import Session
from starlette.exceptions import HTTPException
@ -136,7 +136,7 @@ def top_state_assign(req: Request, host_name: str, state_name: str):
path_labels = host_name.replace("%%2F", "%%2f").split("%%2f")
parent_id = None
for path in path_labels:
host_stmt = select(Host).where(and_(Host.name == path, Host.parent_id == parent_id))
host_stmt = select(Host).where(or_(and_(Host.name == path, Host.parent_id == parent_id, Host.is_hostgroup == True), and_(Host.name == path, Host.is_hostgroup == False, len(path_labels) == 1))) # type: ignore
host_res = db.execute(host_stmt).fetchall()
if len(host_res) != 1: