mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(policy_engine): warn that the config-defined policy reactivates when all DB versions are deleted
This commit is contained in:
parent
35f770f43e
commit
b42ef469cf
2 changed files with 23 additions and 3 deletions
|
|
@ -1031,12 +1031,20 @@ class PolicyRegistry:
|
|||
prisma_client: The Prisma client instance
|
||||
|
||||
Returns:
|
||||
Dict with success message
|
||||
Dict with "message" and optional "warning" if a config-defined policy took over.
|
||||
"""
|
||||
try:
|
||||
await _policy_table(prisma_client).delete_many(where={"policy_name": policy_name})
|
||||
self.remove_policy(policy_name)
|
||||
return {"message": f"All versions of policy '{policy_name}' deleted successfully"}
|
||||
message = f"All versions of policy '{policy_name}' deleted successfully"
|
||||
if self.get_source(policy_name) == "config":
|
||||
return {
|
||||
"message": message,
|
||||
"warning": (
|
||||
"All DB versions were deleted. The config-defined policy with the same name is active again."
|
||||
),
|
||||
}
|
||||
return {"message": message}
|
||||
except Exception as e:
|
||||
verbose_proxy_logger.exception(f"Error deleting all versions: {e}")
|
||||
raise Exception(f"Error deleting all versions: {str(e)}")
|
||||
|
|
|
|||
|
|
@ -613,9 +613,21 @@ class TestRemovePolicyRestoresConfigFallback:
|
|||
prisma = MagicMock()
|
||||
prisma.db.litellm_policytable.delete_many = AsyncMock()
|
||||
|
||||
await registry.delete_all_versions(policy_name="shared-name", prisma_client=prisma)
|
||||
result = await registry.delete_all_versions(policy_name="shared-name", prisma_client=prisma)
|
||||
|
||||
assert registry.get_source("shared-name") == "config"
|
||||
policy = registry.get_policy("shared-name")
|
||||
assert policy is not None
|
||||
assert policy.guardrails.add == ["config-guard"]
|
||||
assert "config" in result["warning"]
|
||||
|
||||
async def test_delete_all_versions_without_config_twin_has_no_warning(self):
|
||||
registry = PolicyRegistry()
|
||||
registry.add_policy("db-only", Policy(guardrails=PolicyGuardrails(add=["db-guard"])), source="db")
|
||||
prisma = MagicMock()
|
||||
prisma.db.litellm_policytable.delete_many = AsyncMock()
|
||||
|
||||
result = await registry.delete_all_versions(policy_name="db-only", prisma_client=prisma)
|
||||
|
||||
assert registry.get_policy("db-only") is None
|
||||
assert "warning" not in result
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue