diff --git a/pillar_tool/routers/pillar.py b/pillar_tool/routers/pillar.py index 27b1b7a..d3d5563 100644 --- a/pillar_tool/routers/pillar.py +++ b/pillar_tool/routers/pillar.py @@ -4,7 +4,7 @@ from uuid import uuid4 from sqlalchemy.dialects import postgresql from sqlalchemy.dialects.postgresql import insert -from sqlalchemy import select, delete, bindparam, and_ +from sqlalchemy import select, delete, bindparam, and_, or_ from sqlalchemy.orm import Session from starlette.exceptions import HTTPException from starlette.requests import Request @@ -184,8 +184,7 @@ def pillar_delete(req: Request, name: str, params: PillarParams): 'message': "Either Host or Hostgroup needs to be set!" }) - # TODO: make this delete recursive - delete_stmt = delete(Pillar).where(and_(Pillar.host_id == target.id, Pillar.pillar_name == name)) + delete_stmt = delete(Pillar).where(and_(Pillar.host_id == target.id, or_(Pillar.pillar_name == name, Pillar.pillar_name.like(f"{name}:%")))) result = db.execute(delete_stmt) return JSONResponse(status_code=200, content={'message': 'ok'})