Skip to content

nautobot.apps.querysets

Nautobot QuerySet classes and utilities.

nautobot.apps.querysets.ConfigContextModelQuerySet

Bases: RestrictedQuerySet

QuerySet manager used by models which support ConfigContext (device and virtual machine).

Includes a method which appends an annotation of aggregated config context JSON data objects. This is implemented as a subquery which performs all the joins necessary to filter relevant config context objects. This offers a substantial performance gain over ConfigContextQuerySet.get_for_object() when dealing with multiple objects.

This allows the annotation to be entirely optional.

annotate_config_context_data()

Attach the subquery annotation to the base queryset.

Order By clause in Subquery is not guaranteed to be respected within the aggregated JSON array, which is why we include "weight" and "name" into the result so that we can sort it within Python to ensure correctness.

TODO This method does not accurately reflect location inheritance because of the reasons stated in _get_config_context_filters() Do not use this method by itself, use get_config_context() method directly on ConfigContextModel instead.