{{{
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%'.
--
Ticket URL: <https://code.djangoproject.com/ticket/29155>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* 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>
* Attachment "29155-test.diff" added.
* cc: felixxm (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:2>
* status: new => assigned
* owner: nobody => felixxm
--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:3>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/9762 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"feb683c4c2c5ecfb61e4cb490c3e357450c0c0e8" feb683c4]:
{{{
#!CommitTicketReference repository=""
revision="feb683c4c2c5ecfb61e4cb490c3e357450c0c0e8"
Fixed #29155 -- Fixed crash when database functions are used with pattern
lookups.
Thanks Tim Graham and Sergey Fedoseev for reviews.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"ba3078c92de6ea3017441c7f503f36e52973ac6b" ba3078c]:
{{{
#!CommitTicketReference repository=""
revision="ba3078c92de6ea3017441c7f503f36e52973ac6b"
Refs #29155 -- Fixed LookupTests.test_pattern_lookups_with_substr() crash
on Oracle.
Test introduced in feb683c4c2c5ecfb61e4cb490c3e357450c0c0e8 revealed
unexpected behavior on Oracle that allows concatenating NULL with string.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:7>