From 82c42dc5db75c23fe28c88a95d5c04566a00d771 Mon Sep 17 00:00:00 2001 From: sevdog Date: Thu, 22 Jun 2023 14:41:48 +0200 Subject: [PATCH] Add compatibility with older django/python versions --- rest_framework/filters.py | 4 ++++ tests/test_filters.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 01437f0f3..375242b6b 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -96,6 +96,10 @@ class SearchFilter(BaseFilterBackend): if hasattr(field, "path_infos"): # Update opts to follow the relation. opts = field.path_infos[-1].to_opts + # django < 4.1 + elif hasattr(field, 'get_path_info'): + # Update opts to follow the relation. + opts = field.get_path_info()[-1].to_opts # Otherwise, use the field with icontains. lookup = 'icontains' return LOOKUP_SEP.join([field_name, lookup]) diff --git a/tests/test_filters.py b/tests/test_filters.py index f8eed4b97..2a87165ca 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -182,7 +182,6 @@ class SearchFilterTests(TestCase): request = factory.get('/', {'search': r'^\w{3}$', 'title_only': 'true'}) response = view(request) - print(response.data) assert response.data == [ {'id': 3, 'title': 'zzz', 'text': 'cde'} ]