From 5fa672b9e90df5858b48acf07adc5380d0356c85 Mon Sep 17 00:00:00 2001 From: qzmalekuz Date: Thu, 26 Feb 2026 14:59:22 +0530 Subject: [PATCH 1/2] Fix: Restrict search indexing to active apps only Search was indexing inactive apps while the detail view requires active=True. This caused search results to link to 404 pages. Override index_queryset() in AppIndex to ensure only active apps are indexed. --- apps/search_indexes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/search_indexes.py b/apps/search_indexes.py index d1f6ac5a2..151495510 100755 --- a/apps/search_indexes.py +++ b/apps/search_indexes.py @@ -32,7 +32,9 @@ class AppIndex(indexes.SearchIndex, indexes.Indexable): def get_model(self): return App - + def index_queryset(self, using=None): + return self.get_model().objects.filter(active=True) + class AuthorIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.EdgeNgramField(document = True, use_template = True) name = indexes.CharField(model_attr = 'name') From 77c083b08da8b548b35244944475b651e5da0e2f Mon Sep 17 00:00:00 2001 From: qzmalekuz Date: Wed, 4 Mar 2026 07:50:55 +0530 Subject: [PATCH 2/2] Fix: Restrict search indexing to active apps and add regression test --- apps/search_indexes.py | 3 ++- apps/tests.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/apps/search_indexes.py b/apps/search_indexes.py index 151495510..673245daa 100755 --- a/apps/search_indexes.py +++ b/apps/search_indexes.py @@ -34,7 +34,8 @@ def get_model(self): def index_queryset(self, using=None): return self.get_model().objects.filter(active=True) - + + class AuthorIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.EdgeNgramField(document = True, use_template = True) name = indexes.CharField(model_attr = 'name') diff --git a/apps/tests.py b/apps/tests.py index e9dfc1803..584ba8b31 100755 --- a/apps/tests.py +++ b/apps/tests.py @@ -12,6 +12,7 @@ import random from PIL import Image, ImageDraw +from apps.search_indexes import AppIndex from django.conf import settings from django.core.files.uploadedfile import SimpleUploadedFile from django.contrib.auth.models import User @@ -676,4 +677,32 @@ def test_app_button_by_name_found_app(self): active=True) appobj.save() res = app_buttons.app_button_by_name('myapp') - self.assertEqual('myapp', res['app'].name) \ No newline at end of file + self.assertEqual('myapp', res['app'].name) + + +class AppIndexQuerysetTestCase(TestCase): + + def setUp(self): + App.objects.all().delete() + + self.active_app = App.objects.create( + name='activeapp', + fullname='ActiveApp', + active=True + ) + + self.inactive_app = App.objects.create( + name='inactiveapp', + fullname='InactiveApp', + active=False + ) + + def tearDown(self): + App.objects.all().delete() + + def test_index_queryset_returns_only_active_apps(self): + index = AppIndex() + queryset = index.index_queryset() + + self.assertIn(self.active_app, queryset) + self.assertNotIn(self.inactive_app, queryset) \ No newline at end of file