mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 01:06:11 -06:00
Fixes #11335: Default manager for ObjectChange should filter by installed apps
This commit is contained in:
parent
bf1c191b2e
commit
51a76b5306
@ -5,7 +5,7 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
from extras.choices import *
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from ..querysets import ObjectChangeManager
|
||||
|
||||
__all__ = (
|
||||
'ObjectChange',
|
||||
@ -82,7 +82,7 @@ class ObjectChange(models.Model):
|
||||
null=True
|
||||
)
|
||||
|
||||
objects = RestrictedQuerySet.as_manager()
|
||||
objects = ObjectChangeManager()
|
||||
|
||||
class Meta:
|
||||
ordering = ['-time']
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.aggregates import JSONBAgg
|
||||
from django.db.models import OuterRef, Subquery, Q
|
||||
from django.db.models import Manager, OuterRef, Subquery, Q
|
||||
|
||||
from extras.models.tags import TaggedItem
|
||||
from utilities.query_functions import EmptyGroupByJSONBAgg
|
||||
@ -151,3 +152,14 @@ class ConfigContextModelQuerySet(RestrictedQuerySet):
|
||||
)
|
||||
|
||||
return base_query
|
||||
|
||||
|
||||
class ObjectChangeManager(Manager.from_queryset(RestrictedQuerySet)):
|
||||
|
||||
def get_queryset(self):
|
||||
# Exclude any change records which refer to an instance of a model that's no longer installed. This
|
||||
# can happen when a plugin is removed but its data remains in the database, for example.
|
||||
app_labels = [
|
||||
app.split('.')[-1] for app in settings.INSTALLED_APPS
|
||||
]
|
||||
return super().get_queryset().filter(changed_object_type__app_label__in=app_labels)
|
||||
|
Loading…
Reference in New Issue
Block a user