Repository: wagtail/wagtail
File: wagtail/admin/views/generic/chooser.py (Python)

Code before:
    """
    Provides common functionality for views that present a (possibly searchable / filterable) list
    of objects to choose from
    """

    per_page = 10
    ordering = None
    chosen_url_name = None
    chosen_multiple_url_name = None
    results_url_name = None
    icon = "snippet"
    page_title = _("Choose")
    filter_form_class = None
    template_name = "wagtailadmin/generic/chooser/chooser.html"
    results_template_name = "wagtailadmin/generic/chooser/results.html"
    construct_queryset_hook_name = None
    url_filter_parameters = []
    paginator_class = WagtailPaginator

    @cached_property
    def i18n_enabled(self) -> bool:
        return getattr(settings, "WAGTAIL_I18N_ENABLED", False) and issubclass(
            self.model_class, TranslatableMixin
        )

    def get_object_list(self):
        return self.model_class.objects.all()

    def apply_object_list_ordering(self, objects):
        if isinstance(self.ordering, (list, tuple)):
            objects = objects.order_by(*self.ordering)
        elif self.ordering:
            objects = objects.order_by(self.ordering)
        elif objects.ordered:
            # Preserve the model-level ordering if specified
            pass
        else:
            # fall back on PK to ensure pagination is consistent
            objects = objects.order_by("pk")

        return objects

    def get_filter_form_class(self):
        if self.filter_form_class:
            return self.filter_form_class
        else:
            bases = [BaseFilterForm]
            if self.model_class:
                if class_is_indexed(self.model_class):
                    bases.insert(0, SearchFilterMixin)
                if issubclass(self.model_class, CollectionMember):

Review comment (suggestion):
The original code had the `issubclass` check inside an `if self.model_class`. There's a possibility that the `model_class` is `None` so we have to check that too

Code after:
    """
    Provides common functionality for views that present a (possibly searchable / filterable) list
    of objects to choose from
    """

    per_page = 10
    ordering = None
    chosen_url_name = None
    chosen_multiple_url_name = None
    results_url_name = None
    icon = "snippet"
    page_title = _("Choose")
    filter_form_class = None
    template_name = "wagtailadmin/generic/chooser/chooser.html"
    results_template_name = "wagtailadmin/generic/chooser/results.html"
    construct_queryset_hook_name = None
    url_filter_parameters = []
    paginator_class = WagtailPaginator

    @cached_property
    def i18n_enabled(self) -> bool:
        return (
            getattr(settings, "WAGTAIL_I18N_ENABLED", False)
            and self.model_class is not None
            and issubclass(self.model_class, TranslatableMixin)
        )

    def get_object_list(self):
        return self.model_class.objects.all()

    def apply_object_list_ordering(self, objects):
        if isinstance(self.ordering, (list, tuple)):
            objects = objects.order_by(*self.ordering)
        elif self.ordering:
            objects = objects.order_by(self.ordering)
        elif objects.ordered:
            # Preserve the model-level ordering if specified
            pass
        else:
            # fall back on PK to ensure pagination is consistent
            objects = objects.order_by("pk")

        return objects

    def get_filter_form_class(self):
        if self.filter_form_class:
            return self.filter_form_class
        else:
            bases = [BaseFilterForm]
            if self.model_class:
                if class_is_indexed(self.model_class):