From 8a1a9194686881e32d0e3aed52d7f4150238530c Mon Sep 17 00:00:00 2001 From: Jaap Roes Date: Fri, 30 Nov 2018 15:42:50 +0100 Subject: [PATCH] Fixed #29997 -- Allowed combining SearchQuerys with different configs. Seems to be a needless restriction in 978a00e39fee25cfa99065285b0de88366710fad. --- django/contrib/postgres/search.py | 2 -- tests/postgres_tests/test_search.py | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py index 635a715250..9cd79623b3 100644 --- a/django/contrib/postgres/search.py +++ b/django/contrib/postgres/search.py @@ -99,8 +99,6 @@ class SearchQueryCombinable: 'SearchQuery can only be combined with other SearchQuerys, ' 'got {}.'.format(type(other)) ) - if not self.config == other.config: - raise TypeError("SearchQuery configs don't match.") if reversed: return CombinedSearchQuery(other, connector, self, self.config) return CombinedSearchQuery(self, connector, other, self.config) diff --git a/tests/postgres_tests/test_search.py b/tests/postgres_tests/test_search.py index 912f17948d..303f4d8783 100644 --- a/tests/postgres_tests/test_search.py +++ b/tests/postgres_tests/test_search.py @@ -276,12 +276,24 @@ class TestCombinations(GrailTestData, PostgreSQLTestCase): searched = Line.objects.filter(character=self.minstrel, dialogue__search=~SearchQuery('kneecaps')) self.assertCountEqual(searched, [self.verse0, self.verse2]) - def test_query_config_mismatch(self): - with self.assertRaisesMessage(TypeError, "SearchQuery configs don't match."): - Line.objects.filter( - dialogue__search=SearchQuery('kneecaps', config='german') | + def test_combine_different_configs(self): + searched = Line.objects.filter( + dialogue__search=( + SearchQuery('cadeau', config='french') | SearchQuery('nostrils', config='english') ) + ) + self.assertCountEqual(searched, [self.french, self.verse2]) + + @skipUnlessDBFeature('has_phraseto_tsquery') + def test_combine_raw_phrase(self): + searched = Line.objects.filter( + dialogue__search=( + SearchQuery('burn:*', search_type='raw', config='simple') | + SearchQuery('rode forth from Camelot', search_type='phrase') + ) + ) + self.assertCountEqual(searched, [self.verse0, self.verse1, self.verse2]) def test_query_combined_mismatch(self): msg = "SearchQuery can only be combined with other SearchQuerys, got"