From 644a03e40ee889ac1f925234f9823b2ee390aaad Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 1 Mar 2021 19:23:09 +0100 Subject: [PATCH] lib: don't order_by on widget because PolicyBindingModel, order in form --- authentik/core/forms/applications.py | 2 +- authentik/flows/forms.py | 3 ++- authentik/lib/widgets.py | 2 +- authentik/policies/forms.py | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/authentik/core/forms/applications.py b/authentik/core/forms/applications.py index b5ff6fba3..94bbfdfb9 100644 --- a/authentik/core/forms/applications.py +++ b/authentik/core/forms/applications.py @@ -12,7 +12,7 @@ class ApplicationForm(forms.ModelForm): def __init__(self, *args, **kwargs): # pragma: no cover super().__init__(*args, **kwargs) self.fields["provider"].queryset = ( - Provider.objects.all().order_by("pk").select_subclasses() + Provider.objects.all().order_by("name").select_subclasses() ) class Meta: diff --git a/authentik/flows/forms.py b/authentik/flows/forms.py index c639a0d5e..2e8ca9d14 100644 --- a/authentik/flows/forms.py +++ b/authentik/flows/forms.py @@ -34,7 +34,8 @@ class FlowStageBindingForm(forms.ModelForm): """FlowStageBinding Form""" stage = GroupedModelChoiceField( - queryset=Stage.objects.all().select_subclasses(), to_field_name="stage_uuid" + queryset=Stage.objects.all().order_by("name").select_subclasses(), + to_field_name="stage_uuid", ) def __init__(self, *args, **kwargs): diff --git a/authentik/lib/widgets.py b/authentik/lib/widgets.py index 2fb833941..f2104313b 100644 --- a/authentik/lib/widgets.py +++ b/authentik/lib/widgets.py @@ -10,7 +10,7 @@ class GroupedModelChoiceIterator(ModelChoiceIterator): def __iter__(self): if self.field.empty_label is not None: yield ("", self.field.empty_label) - queryset = self.queryset.order_by("name") + queryset = self.queryset # Can't use iterator() when queryset uses prefetch_related() if not queryset._prefetch_related_lookups: queryset = queryset.iterator() diff --git a/authentik/policies/forms.py b/authentik/policies/forms.py index f6c63b080..656358fbc 100644 --- a/authentik/policies/forms.py +++ b/authentik/policies/forms.py @@ -15,7 +15,8 @@ class PolicyBindingForm(forms.ModelForm): to_field_name="pbm_uuid", ) policy = GroupedModelChoiceField( - queryset=Policy.objects.all().select_subclasses(), required=False + queryset=Policy.objects.all().order_by("name").select_subclasses(), + required=False, ) group = forms.ModelChoiceField( queryset=Group.objects.all().order_by("name"), required=False