Просмотр исходного кода

Fixes #21747: Skip search caching when encountering an invalid schema during migrations (#21748)

Jeremy Stretch 1 день назад
Родитель
Сommit
b929e1aa1b
1 измененных файлов с 10 добавлено и 1 удалено
  1. 10 1
      netbox/netbox/search/backends.py

+ 10 - 1
netbox/netbox/search/backends.py

@@ -1,9 +1,11 @@
+import logging
 from collections import defaultdict
 
 import netaddr
 from django.conf import settings
 from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import ImproperlyConfigured
+from django.db import ProgrammingError
 from django.db.models import F, Q, Window, prefetch_related_objects
 from django.db.models.fields.related import ForeignKey
 from django.db.models.functions import window
@@ -24,6 +26,8 @@ from . import FieldTypes, LookupTypes, get_indexer
 DEFAULT_LOOKUP_TYPE = LookupTypes.PARTIAL
 MAX_RESULTS = 1000
 
+logger = logging.getLogger(__name__)
+
 
 class SearchBackend:
     """
@@ -63,7 +67,12 @@ class SearchBackend:
         """
         Receiver for the post_save signal, responsible for caching object creation/changes.
         """
-        self.cache(instance, remove_existing=not created)
+        try:
+            self.cache(instance, remove_existing=not created)
+        except ProgrammingError as e:
+            # The schema may be incomplete during migrations; skip caching.
+            logger.warning(f"Skipping search cache update due to schema error: {e}")
+            pass
 
     def removal_handler(self, sender, instance, **kwargs):
         """