From 1f18188b8689d9fd7d9d4fac99eb95272f4fc96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Bellon-Gervais?= Date: Thu, 4 Jun 2026 16:18:57 +0200 Subject: [PATCH] fix(attachment_registry): preserve config-loaded policies across DB sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Grégoire Bellon-Gervais --- litellm/proxy/policy_engine/attachment_registry.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/policy_engine/attachment_registry.py b/litellm/proxy/policy_engine/attachment_registry.py index 8d5d8116919..37f01b3ed2d 100644 --- a/litellm/proxy/policy_engine/attachment_registry.py +++ b/litellm/proxy/policy_engine/attachment_registry.py @@ -41,6 +41,7 @@ class AttachmentRegistry: def __init__(self): self._attachments: List[PolicyAttachment] = [] + self._config_attachments: List[PolicyAttachment] = [] self._initialized: bool = False def load_attachments(self, attachments_config: List[Dict[str, Any]]) -> None: @@ -51,11 +52,13 @@ class AttachmentRegistry: attachments_config: List of attachment dictionaries from YAML. """ self._attachments = [] + self._config_attachments = [] for attachment_data in attachments_config: try: attachment = self._parse_attachment(attachment_data) self._attachments.append(attachment) + self._config_attachments.append(attachment) verbose_proxy_logger.debug( f"Loaded attachment for policy: {attachment.policy}" ) @@ -210,6 +213,7 @@ class AttachmentRegistry: Clear all attachments from the registry. """ self._attachments = [] + self._config_attachments = [] self._initialized = False def add_attachment(self, attachment: PolicyAttachment) -> None: @@ -452,14 +456,17 @@ class AttachmentRegistry: """ Sync policy attachments from the database to in-memory registry. + Preserves config-loaded attachments so a DB sync with no results does not + wipe them. DB entries are merged on top of config attachments. + Args: prisma_client: The Prisma client instance """ try: attachments = await self.get_all_attachments_from_db(prisma_client) - # Clear existing attachments and reload from DB - self._attachments = [] + # Start with config-loaded attachments (preserve YAML-defined ones) + self._attachments = list(self._config_attachments) for attachment_response in attachments: attachment = PolicyAttachment( @@ -480,7 +487,8 @@ class AttachmentRegistry: self._initialized = True verbose_proxy_logger.info( - f"Synced {len(attachments)} attachments from DB to in-memory registry" + f"Synced {len(attachments)} DB attachments + " + f"{len(self._config_attachments)} config attachments to in-memory registry" ) except Exception as e: verbose_proxy_logger.exception(f"Error syncing attachments from DB: {e}")