From 5e32c82a5a896e1d942cfc9dd9a2ebbe86741258 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Mon, 27 Jul 2026 23:25:12 +0100 Subject: [PATCH] Refs #22712 -- Restored django.contrib.staticfiles.finders.BaseFinder.find(). This was overzealously removed in a146fe293099d7f860ba13e4b3a571bbda55af22. --- django/contrib/staticfiles/finders.py | 11 +++++++++++ tests/staticfiles_tests/test_finders.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py index 80ec9e3c48a8..96eb7e71ddbb 100644 --- a/django/contrib/staticfiles/finders.py +++ b/django/contrib/staticfiles/finders.py @@ -26,6 +26,17 @@ def check(self, **kwargs): "configured correctly." ) + def find(self, path, find_all=False): + """ + Given a relative file path, find an absolute file path. + + If the ``find_all`` parameter is False (default) return only the first + found file path; if True, return a list of all found files paths. + """ + raise NotImplementedError( + "subclasses of BaseFinder must provide a find() method" + ) + def list(self, ignore_patterns): """ Given an optional list of paths to ignore, return a two item iterable diff --git a/tests/staticfiles_tests/test_finders.py b/tests/staticfiles_tests/test_finders.py index 7efe86ab6a08..7ab3cd035082 100644 --- a/tests/staticfiles_tests/test_finders.py +++ b/tests/staticfiles_tests/test_finders.py @@ -9,6 +9,20 @@ from .settings import TEST_ROOT +class TestBaseFinder(SimpleTestCase): + def test_find(self): + finder = finders.BaseFinder() + msg = "subclasses of BaseFinder must provide a find() method" + with self.assertRaisesMessage(NotImplementedError, msg): + finder.find("file.txt") + + def test_list(self): + finder = finders.BaseFinder() + msg = "subclasses of BaseFinder must provide a list() method" + with self.assertRaisesMessage(NotImplementedError, msg): + finder.list(None) + + class TestFinders: """ Base finder test mixin.