mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix(guardrails): add pending_review status guard to reject endpoint
Prevent rejecting already-active or already-rejected guardrails, which would create a DB/memory inconsistency (active in memory but rejected in DB). Now mirrors the approve endpoint's status check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
62f903c0a2
commit
0b31181aa8
2 changed files with 20 additions and 0 deletions
|
|
@ -956,6 +956,11 @@ async def reject_guardrail_submission(
|
|||
raise HTTPException(
|
||||
status_code=404, detail="Guardrail submission not found"
|
||||
)
|
||||
if row.status != "pending_review":
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Guardrail is not pending review (status={row.status})",
|
||||
)
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
await prisma_client.db.litellm_guardrailstable.update(
|
||||
|
|
|
|||
|
|
@ -1376,6 +1376,21 @@ async def test_reject_guardrail_submission_success(mocker):
|
|||
assert call_data["status"] == "rejected"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reject_guardrail_submission_not_pending(mocker):
|
||||
"""Reject returns 400 when status is not pending_review (e.g. already active)."""
|
||||
mock_prisma = mocker.Mock()
|
||||
row = mocker.Mock(guardrail_id="already-active", guardrail_name="g", status="active")
|
||||
mock_prisma.db.litellm_guardrailstable.find_unique = AsyncMock(return_value=row)
|
||||
mocker.patch("litellm.proxy.proxy_server.prisma_client", mock_prisma)
|
||||
user = UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await reject_guardrail_submission("already-active", user)
|
||||
assert exc_info.value.status_code == 400
|
||||
assert "not pending review" in exc_info.value.detail.lower()
|
||||
|
||||
|
||||
# --- Tests for review fixes ---
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue