mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix: req changes on rollback
This commit is contained in:
parent
465c9a14f8
commit
7481473cd4
2 changed files with 23 additions and 10 deletions
|
|
@ -556,11 +556,12 @@ async def delete_guardrail(
|
|||
verbose_proxy_logger.error(
|
||||
f"Immediate sync: Failed to remove guardrail '{guardrail_name}' (ID: {guardrail_id}) from memory: {delete_error}"
|
||||
)
|
||||
# Rollback: re-create the DB entry so state stays consistent
|
||||
# Rollback: re-create the DB entry with the ORIGINAL guardrail_id
|
||||
try:
|
||||
await GUARDRAIL_REGISTRY.add_guardrail_to_db(
|
||||
guardrail=cast(Guardrail, existing_guardrail),
|
||||
prisma_client=prisma_client,
|
||||
guardrail_id=guardrail_id,
|
||||
)
|
||||
except Exception:
|
||||
verbose_proxy_logger.error(
|
||||
|
|
|
|||
|
|
@ -234,10 +234,18 @@ class GuardrailRegistry:
|
|||
########### DB management helpers for guardrails ###########
|
||||
############################################################
|
||||
async def add_guardrail_to_db(
|
||||
self, guardrail: Guardrail, prisma_client: PrismaClient
|
||||
self,
|
||||
guardrail: Guardrail,
|
||||
prisma_client: PrismaClient,
|
||||
guardrail_id: Optional[str] = None,
|
||||
):
|
||||
"""
|
||||
Add a guardrail to the database
|
||||
Add a guardrail to the database.
|
||||
|
||||
Args:
|
||||
guardrail_id: If provided, the row is created with this specific ID
|
||||
(used by rollback paths to restore a deleted row with
|
||||
its original ID).
|
||||
"""
|
||||
try:
|
||||
guardrail_name = guardrail.get("guardrail_name")
|
||||
|
|
@ -252,15 +260,19 @@ class GuardrailRegistry:
|
|||
litellm_params: str = safe_dumps(litellm_params_dict)
|
||||
guardrail_info: str = safe_dumps(guardrail.get("guardrail_info", {}))
|
||||
|
||||
create_data: Dict[str, Any] = {
|
||||
"guardrail_name": guardrail_name,
|
||||
"litellm_params": litellm_params,
|
||||
"guardrail_info": guardrail_info,
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
"updated_at": datetime.now(timezone.utc),
|
||||
}
|
||||
if guardrail_id is not None:
|
||||
create_data["guardrail_id"] = guardrail_id
|
||||
|
||||
# Create guardrail in DB
|
||||
created_guardrail = await prisma_client.db.litellm_guardrailstable.create(
|
||||
data={
|
||||
"guardrail_name": guardrail_name,
|
||||
"litellm_params": litellm_params,
|
||||
"guardrail_info": guardrail_info,
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
"updated_at": datetime.now(timezone.utc),
|
||||
}
|
||||
data=create_data
|
||||
)
|
||||
|
||||
# Add guardrail_id to the returned guardrail object
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue