[Django] #29155: Using contains field lookup with Substr database function cause modification of second parameter of Substr

11 views
Skip to first unread message

Django

unread,
Feb 23, 2018, 4:07:57 PM2/23/18
to django-...@googlegroups.com
#29155: Using contains field lookup with Substr database function cause
modification of second parameter of Substr
-------------------------------------+-------------------------------------
Reporter: norac89 | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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%'.

--
Ticket URL: <https://code.djangoproject.com/ticket/29155>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 23, 2018, 7:14:58 PM2/23/18
to django-...@googlegroups.com
#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

unread,
Feb 23, 2018, 7:15:12 PM2/23/18
to django-...@googlegroups.com
#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):

* Attachment "29155-test.diff" added.

Django

unread,
Feb 24, 2018, 9:54:22 AM2/24/18
to django-...@googlegroups.com
#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 felixxm):

* cc: felixxm (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:2>

Django

unread,
Feb 24, 2018, 10:28:31 AM2/24/18
to django-...@googlegroups.com
#29155: Using contains lookup with Substr causes modification of second parameter
of Substr
-------------------------------------+-------------------------------------
Reporter: norac89 | Owner: felixxm
Type: Bug | Status: assigned

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 felixxm):

* status: new => assigned
* owner: nobody => felixxm


--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:3>

Django

unread,
Mar 7, 2018, 3:25:04 PM3/7/18
to django-...@googlegroups.com
#29155: Using contains lookup with Substr causes modification of second parameter
of Substr
-------------------------------------+-------------------------------------

Reporter: norac89 | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9762 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:4>

Django

unread,
Mar 13, 2018, 9:07:01 PM3/13/18
to django-...@googlegroups.com
#29155: Using contains lookup with Substr causes modification of second parameter
of Substr
-------------------------------------+-------------------------------------

Reporter: norac89 | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
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
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29155#comment:5>

Django

unread,
Mar 14, 2018, 5:00:49 AM3/14/18
to django-...@googlegroups.com
#29155: Using contains lookup with Substr causes modification of second parameter
of Substr
-------------------------------------+-------------------------------------
Reporter: norac89 | Owner: felixxm
Type: Bug | Status: closed

Component: Database layer | Version: 2.0
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* 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>

Django

unread,
Mar 15, 2018, 9:54:44 AM3/15/18
to django-...@googlegroups.com
#29155: Using contains lookup with Substr causes modification of second parameter
of Substr
-------------------------------------+-------------------------------------

Reporter: norac89 | Owner: felixxm
Type: Bug | Status: closed
Component: Database layer | Version: 2.0
(models, ORM) |
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 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>

Reply all
Reply to author
Forward
0 new messages