Skip to content

Commit bc7678c

Browse files
abhi1693jeremystretch
authored andcommitted
fixes content type lookups when db is uninitialized #13116
1 parent 63c33ff commit bc7678c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

netbox/extras/querysets.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.contrib.contenttypes.models import ContentType
33
from django.contrib.postgres.aggregates import JSONBAgg
44
from django.db.models import OuterRef, Subquery, Q
5+
from django.db.utils import ProgrammingError
56

67
from extras.models.tags import TaggedItem
78
from utilities.query_functions import EmptyGroupByJSONBAgg
@@ -160,7 +161,13 @@ class ObjectChangeQuerySet(RestrictedQuerySet):
160161
def valid_models(self):
161162
# Exclude any change records which refer to an instance of a model that's no longer installed. This
162163
# can happen when a plugin is removed but its data remains in the database, for example.
164+
try:
165+
content_types = ContentType.objects.get_for_models(*apps.get_models()).values()
166+
except ProgrammingError:
167+
# Handle the case where the database schema has not yet been initialized
168+
content_types = ContentType.objects.none()
169+
163170
content_type_ids = set(
164-
ct.pk for ct in ContentType.objects.get_for_models(*apps.get_models()).values()
171+
ct.pk for ct in content_types
165172
)
166173
return self.filter(changed_object_type_id__in=content_type_ids)

0 commit comments

Comments
 (0)