#29155: Using contains lookup with Substr causes modification of second
parameter
of Substr
-------------------------------------+-------------------------------------
Reporter: norac89 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
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):
* stage: Unreviewed => Accepted
Old description:
> My model:
>
> {{{
> class User(models.Model):
> field1 = models.Charfield(max_length=120)
> field2 = models.Charfield(max_length=120)
> }}}
>
> Tried querying the model to get User instances in which field2 start with
> the three first characters of field1.
> Tried the following:
>
> {{{
> User.objects.filter(field2__startswith=Substr(F('field1'), 1, 3))
> }}}
>
> I m getting the following error
>
> {{{
> psycopg2.DataError: invalid input syntax for integer: "1%"
> LINE 1: ...(REPLACE(REPLACE((SUBSTRING("test_user"."field1", '1%',
> 3)),...
> }}}
>
> The second parameter of the substr function seems to be replaced with
> '1%'.
New description:
My model:
{{{
class User(models.Model):
field1 = models.CharField(max_length=120)
field2 = models.CharField(max_length=120)
}}}
Tried querying the model to get User instances in which field2 start with
the three first characters of field1.
Tried the following:
{{{
User.objects.filter(field2__startswith=Substr(F('field1'), 1, 3))
}}}
I m getting the following error
{{{
psycopg2.DataError: invalid input syntax for integer: "1%"
LINE 1: ...(REPLACE(REPLACE((SUBSTRING("test_user"."field1", '1%', 3)),...
}}}
The second parameter of the substr function seems to be replaced with
'1%'.
--
Comment:
I'm attaching a test for Django's test suite that fails (on PostgreSQL but
not SQLite) as of ba37ee9ef882deb8e917f1cae0c586a0a275e731.
--
Ticket URL: <https://code.djangoproject.com/ticket/29155#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/065.84a65ec5e8a8f56d823d33bdd74a6193%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.