#29582: SearchVector doesn't support querying non-text fields
----------------------------------+------------------------------------
     Reporter:  mickaelmarin      |                    Owner:  nobody
         Type:  Bug               |                   Status:  new
    Component:  contrib.postgres  |                  Version:  1.11
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Accepted
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+------------------------------------
Changes (by Tim Graham):

 * component:  Uncategorized => contrib.postgres
 * stage:  Unreviewed => Accepted
 * type:  Uncategorized => Bug


Old description:

> Hi,
>
> I try to implement autocomplete on my place table that look like below:
>
> **  class Place(models.Model):
>     name = models.CharField(max_length=80, blank=True)
>     num = models.IntegerField(null=True)
>     street = models.CharField(max_length=100, blank=True)
>     postal_code = models.IntegerField(null=True)
>     district = models.CharField(max_length=30, blank=True)
>     city=models.CharField(max_length=30, blank=True)
>     country = models.CharField(max_length=30, blank=True)
>     domicile = models.BooleanField(default=False)
>
>     def __str__(self):
>         address = "{0}, {1}, {2}, {3}".format(self.num, self.street,
>                                               self.postal_code,
> self.city, self.country)
>         return address**
>
> and in my function that return the result for display my address on
> frontend is like (self.q is a GET param from ajax call):
>
> **qs = Place.objects.all()
> qs.annotate(search=SearchVector('street', 'country','city',
> 'num')).filter(search__icontains=self.q)**
>

> I have this error when the ajax call run:
>
>   File "/opt/coupdepouce/lib/python3.6/site-
> packages/django/db/backends/utils.py", line 64, in execute
>     return self.cursor.execute(sql, params)
> django.db.utils.DataError: invalid input syntax for integer: ""
> LINE 1: ...city", '') || ' ' || COALESCE("user_place"."num", '')) AS
> "s...

New description:

 I try to implement autocomplete on my place table that look like below:
 {{{
 class Place(models.Model):
     name = models.CharField(max_length=80, blank=True)
     num = models.IntegerField(null=True)
     street = models.CharField(max_length=100, blank=True)
     postal_code = models.IntegerField(null=True)
     district = models.CharField(max_length=30, blank=True)
     city=models.CharField(max_length=30, blank=True)
     country = models.CharField(max_length=30, blank=True)
     domicile = models.BooleanField(default=False)

     def __str__(self):
         address = "{0}, {1}, {2}, {3}".format(self.num, self.street,
                                               self.postal_code, self.city,
 self.country)
         return address
 }}}
 and in my function that return the result for display my address on
 frontend is like (self.q is a GET param from ajax call):

 {{{
 qs = Place.objects.all()
 qs.annotate(search=SearchVector('street', 'country','city',
 'num')).filter(search__icontains=self.q)
 }}}
 I have this error when the ajax call run:
 {{{
   File "/opt/coupdepouce/lib/python3.6/site-
 packages/django/db/backends/utils.py", line 64, in execute
     return self.cursor.execute(sql, params)
 django.db.utils.DataError: invalid input syntax for integer: ""
 LINE 1: ...city", '') || ' ' || COALESCE("user_place"."num", '')) AS "s...
 }}}

--

Comment:

 The problem seems to be
 
[https://github.com/django/django/blob/ba83378a7762c51be235b521aa5b48233d6c6c82/django/contrib/postgres/search.py#L56the
 hardcoded] `Value('')`, regardless of the field type. I'm not sure what
 the proper resolution is.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29582#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.798ecff8c94c42cfdb520ec6f49ab5a3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to