Use get_queryset functions when using valid_models to force re-evaluation #11481

Closed
opened 2025-12-29 21:45:50 +01:00 by adam · 1 comment
Owner

Originally created by @arthanson on GitHub (Aug 14, 2025).

Originally assigned to: @arthanson on GitHub.

Proposed Changes

The code currently defines queryset using valid_models as class variables like the following:

class ObjectChangeListView(generic.ObjectListView):
    queryset = ObjectChange.objects.valid_models()

instead define these as get_queryset functions that return ObjectChange.objects.valid_models()

Justification

valid_models creates a set of content types and then returns a filtered list of ObjectTypes. The problem is that when defined as class variables this is only done when the class is instantiated and not when requested, so any potential changes to ContentTypes after instantiation is not picked up.

Originally created by @arthanson on GitHub (Aug 14, 2025). Originally assigned to: @arthanson on GitHub. ### Proposed Changes The code currently defines queryset using valid_models as class variables like the following: ``` class ObjectChangeListView(generic.ObjectListView): queryset = ObjectChange.objects.valid_models() ``` instead define these as get_queryset functions that return `ObjectChange.objects.valid_models()` ### Justification valid_models creates a set of content types and then returns a filtered list of ObjectTypes. The problem is that when defined as class variables this is only done when the class is instantiated and not when requested, so any potential changes to ContentTypes after instantiation is not picked up.
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:45:50 +01:00
adam closed this issue 2025-12-29 21:45:50 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 14, 2025):

Reclassifying this as a feature request

@jeremystretch commented on GitHub (Aug 14, 2025): Reclassifying this as a feature request
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11481