diff --git a/netbox/extras/querysets.py b/netbox/extras/querysets.py index fbe7fe903..3710bec46 100644 --- a/netbox/extras/querysets.py +++ b/netbox/extras/querysets.py @@ -1,7 +1,8 @@ +from django.contrib.postgres.aggregates import JSONBAgg from django.db.models import OuterRef, Subquery, Q from extras.models.tags import TaggedItem -from utilities.query_functions import EmptyGroupByJSONBAgg, OrderableJSONBAgg +from utilities.query_functions import EmptyGroupByJSONBAgg from utilities.querysets import RestrictedQuerySet @@ -47,7 +48,7 @@ class ConfigContextQuerySet(RestrictedQuerySet): if aggregate_data: return queryset.aggregate( - config_context_data=OrderableJSONBAgg('data', ordering=['weight', 'name']) + config_context_data=JSONBAgg('data', ordering=['weight', 'name']) )['config_context_data'] return queryset diff --git a/netbox/ipam/tests/test_views.py b/netbox/ipam/tests/test_views.py index db96bb896..b105ea7d9 100644 --- a/netbox/ipam/tests/test_views.py +++ b/netbox/ipam/tests/test_views.py @@ -210,6 +210,7 @@ class PrefixTestCase(ViewTestCases.PrimaryObjectViewTestCase): Role(name='Role 1', slug='role-1'), Role(name='Role 2', slug='role-2'), ) + Role.objects.bulk_create(roles) Prefix.objects.bulk_create([ Prefix(prefix=IPNetwork('10.1.0.0/16'), vrf=vrfs[0], site=sites[0], role=roles[0]), diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 604b755d8..c1447808e 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -375,6 +375,8 @@ LOGIN_URL = '/{}login/'.format(BASE_PATH) CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS +DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' + # Exclude potentially sensitive models from wildcard view exemption. These may still be exempted # by specifying the model individually in the EXEMPT_VIEW_PERMISSIONS configuration parameter. EXEMPT_EXCLUDE_MODELS = ( diff --git a/netbox/utilities/query_functions.py b/netbox/utilities/query_functions.py index abdc61b6b..8ad7ceead 100644 --- a/netbox/utilities/query_functions.py +++ b/netbox/utilities/query_functions.py @@ -1,5 +1,4 @@ from django.contrib.postgres.aggregates import JSONBAgg -from django.contrib.postgres.aggregates.mixins import OrderableAggMixin from django.db.models import F, Func @@ -11,19 +10,10 @@ class CollateAsChar(Func): template = '(%(expressions)s) COLLATE "%(function)s"' -class OrderableJSONBAgg(OrderableAggMixin, JSONBAgg): - """ - TODO in Django 3.2 ordering is supported natively on JSONBAgg so this is no longer needed. - """ - template = '%(function)s(%(distinct)s%(expressions)s %(ordering)s)' - - -class EmptyGroupByJSONBAgg(OrderableJSONBAgg): +class EmptyGroupByJSONBAgg(JSONBAgg): """ JSONBAgg is a builtin aggregation function which means it includes the use of a GROUP BY clause. When used as an annotation for collecting config context data objects, the GROUP BY is incorrect. This subclass overrides the Django ORM aggregation control to remove the GROUP BY. - - TODO in Django 3.2 ordering is supported natively on JSONBAgg so we only need to inherit from JSONBAgg. """ contains_aggregate = False diff --git a/requirements.txt b/requirements.txt index 18ce530fd..f9e616c5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==3.1.3 +Django==3.2b1 django-cacheops==5.1 django-cors-headers==3.5.0 django-debug-toolbar==3.1.1