#31340: Improve expression support for __search lookup and SearchQuery
-------------------------------------+-------------------------------------
     Reporter:  Baptiste Mispelon    |                    Owner:  Baptiste
                                     |  Mispelon
         Type:  New feature          |                   Status:  closed
    Component:  contrib.postgres     |                  Version:  dev
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

 I think the patch should have checked `output_field` instead of special
 casing `SearchQuery` and `CombinedSearchQuery` in this form

 {{{#!patch
 diff --git a/django/contrib/postgres/search.py
 b/django/contrib/postgres/search.py
 index 2135c9bb88..636123a3ed 100644
 --- a/django/contrib/postgres/search.py
 +++ b/django/contrib/postgres/search.py
 @@ -16,7 +16,10 @@ class SearchVectorExact(Lookup):
      lookup_name = "exact"

      def process_rhs(self, qn, connection):
 -        if not isinstance(self.rhs, (SearchQuery, CombinedSearchQuery)):
 +        if not isinstance(
 +            getattr(self.rhs, "_output_field_or_none", None),
 +            SearchQueryField,
 +        ):
              config = getattr(self.lhs, "config", None)
              self.rhs = SearchQuery(self.rhs, config=config)
          rhs, rhs_params = super().process_rhs(qn, connection)
 @@ -240,6 +243,15 @@ def __str__(self):
          return "(%s)" % super().__str__()


 +register_combinable_fields(
 +    SearchQueryField, SearchQueryCombinable.BITAND, SearchQueryField,
 SearchQueryField
 +)
 +
 +register_combinable_fields(
 +    SearchQueryField, SearchQueryCombinable.BITOR, SearchQueryField,
 SearchQueryField
 +)
 +
 +
  class SearchRank(Func):
      function = "ts_rank"
      output_field = FloatField()
 }}}

 as in its current form it disallows usage of
 `Func(output_field=SearchQueryField())`.

 Happy to accept a new ticket with the above if you're willing to write
 tests, in the mean time your best bet is likely to subclass `SearchQuery`
 and override `__init__` to assign `my_tsquery_func` instead and support a
 different signature.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/31340#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070196fe42c369-7cfbd418-8432-4538-824f-78d60b5ac827-000000%40eu-central-1.amazonses.com.

Reply via email to