Ticket #31304: patch-django-2.2.9-postgres-search.diff

File patch-django-2.2.9-postgres-search.diff, 1.2 KB (added by Paul Boddie, 5 years ago)
  • django/contrib/postgres/search.py

     
    6767                resolved.config = self.config.resolve_expression(query, allow_joins, reuse, summarize, for_save)
    6868        return resolved
    6969
     70    def textual_expression(self, expression):
     71        if isinstance(expression.output_field, (CharField, TextField)):
     72            return expression
     73        else:
     74            return Cast(expression, TextField())
     75
    7076    def as_sql(self, compiler, connection, function=None, template=None):
    7177        clone = self.copy()
    7278        clone.set_source_expressions([
    73             Coalesce(
    74                 expression
    75                 if isinstance(expression.output_field, (CharField, TextField))
    76                 else Cast(expression, TextField()),
    77                 Value('')
     79            (
     80                # Coalesce nullable fields only.
     81                Coalesce(self.textual_expression(expression), Value(''))
     82                if expression.output_field.null
     83                else self.textual_expression(expression)
    7884            ) for expression in clone.get_source_expressions()
    7985        ])
    8086        config_params = []
Back to Top