summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/search.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2020-02-24 23:48:07 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-26 08:03:46 +0100
commitd0f1c03331718f1b146cf0fd6ffefa19538eebe4 (patch)
tree4025d1dcf1a1bde07d58bccaf8c378582f564b74 /django/contrib/postgres/search.py
parent3d62ddb02695cfafc847951b45e6e1ec5dc0b149 (diff)
downloaddjango-d0f1c03331718f1b146cf0fd6ffefa19538eebe4.tar.gz
Refs #31211 -- Prevented SearchConfig nesting in SearchVector and SearchQuery init.
Passing a SearchConfig instance directly to SearchVector and SearchQuery would result in nested SearchConfig instance.
Diffstat (limited to 'django/contrib/postgres/search.py')
-rw-r--r--django/contrib/postgres/search.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py
index dceda6c8da..19a0ca777c 100644
--- a/django/contrib/postgres/search.py
+++ b/django/contrib/postgres/search.py
@@ -41,6 +41,12 @@ class SearchConfig(Expression):
config = Value(config)
self.config = config
+ @classmethod
+ def from_parameter(cls, config):
+ if config is None or isinstance(config, cls):
+ return config
+ return cls(config)
+
def get_source_expressions(self):
return [self.config]
@@ -75,7 +81,7 @@ class SearchVector(SearchVectorCombinable, Func):
def __init__(self, *expressions, **extra):
super().__init__(*expressions, **extra)
config = self.extra.get('config', self.config)
- self.config = SearchConfig(config) if config else None
+ self.config = SearchConfig.from_parameter(config)
weight = self.extra.get('weight')
if weight is not None and not hasattr(weight, 'resolve_expression'):
weight = Value(weight)
@@ -162,7 +168,7 @@ class SearchQuery(SearchQueryCombinable, Value):
}
def __init__(self, value, output_field=None, *, config=None, invert=False, search_type='plain'):
- self.config = SearchConfig(config) if config else None
+ self.config = SearchConfig.from_parameter(config)
self.invert = invert
if search_type not in self.SEARCH_TYPES:
raise ValueError("Unknown search_type argument '%s'." % search_type)