[Django] #31271: Logged ORM query differs from executed one

9 views
Skip to first unread message

Django

unread,
Feb 14, 2020, 3:32:35 AM2/14/20
to django-...@googlegroups.com
#31271: Logged ORM query differs from executed one
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
HansAarneLiblik |
Type: Bug | Status: new
Component: | Version: 3.0
Uncategorized | Keywords: oracle sql log
Severity: Normal | debug logging
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When making a query

{{{
MyObject.objects.filter(field1='value1').exclude(field2__in=['badValue1',
'badValue2'])
}}}

{{{
django/db/backends/oracle/base.py 'def _fix_for_params()'
}}}
gets params as
{{{
tuple('value1', 'badValue1', 'badValue2')
}}}
and then makes them into a set
{{{
enumerate(set(params))
}}}
. This changes the order of params, and assigns them key (i.e arg0, arg1,
..). This also changes the SQL query and replaces '%s' with param key's
(':arg0', ..). The order or param keys in SQL might not be in order
anymore.

After SQL is executed this statement is logged. But for logging in
{{{
django/db/backends/oracle/operations.py 'def last_executed_query()'
}}}
The code is replacing param keys in SQL (':arg0', ..) with params, but
they do not match anymore, since they are not in order in SQL statement
anymore

REproducable all the time with more than 1 param for SQL

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

Django

unread,
Feb 14, 2020, 4:22:38 AM2/14/20
to django-...@googlegroups.com
#31271: Logged queries may interpolate parameters in the wrong order on Oracle.
-------------------------------------+-------------------------------------
Reporter: Hans Aarne Liblik | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: oracle sql log | Triage Stage: Accepted
debug logging |
Has patch: 0 | Needs documentation: 0

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

* component: Uncategorized => Database layer (models, ORM)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for this report. `last_execute_query()` didn't interpolate
parameters before 79065b55a70cd220820a260a1c54851b7be0615a, so we can
treat this as a regression. It seems that the only reasonable solution is
to use mechanism that preserves ordering in `_fix_for_params()`, but it
can be tricky to add a regression test. I was not able to reproduce an
incorrect behavior but I agree that this can happen.

Would you like to prepare a patch?

--
Ticket URL: <https://code.djangoproject.com/ticket/31271#comment:1>

Django

unread,
Feb 14, 2020, 6:21:54 AM2/14/20
to django-...@googlegroups.com
#31271: Logged queries may interpolate parameters in the wrong order on Oracle.
-------------------------------------+-------------------------------------
Reporter: Hans Aarne Liblik | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: oracle sql log | Triage Stage: Accepted
debug logging |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hans Aarne Liblik):

Sadly, I don't have the knowhow.

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

Django

unread,
Feb 14, 2020, 6:27:46 AM2/14/20
to django-...@googlegroups.com
#31271: Logged queries may interpolate parameters in the wrong order on Oracle.
-------------------------------------+-------------------------------------
Reporter: Hans Aarne Liblik | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: oracle sql log | Triage Stage: Accepted
debug logging |
Has patch: 0 | Needs documentation: 0

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

* cc: Marti Raudsepp (added)


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

Django

unread,
Feb 15, 2020, 6:24:14 AM2/15/20
to django-...@googlegroups.com
#31271: Logged queries may interpolate parameters in the wrong order on Oracle.
-------------------------------------+-------------------------------------
Reporter: Hans Aarne Liblik | Owner: felixxm
Type: Bug | Status: assigned

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: oracle sql log | Triage Stage: Accepted
debug logging |
Has patch: 0 | Needs documentation: 0

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

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


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

Django

unread,
Feb 18, 2020, 3:39:08 AM2/18/20
to django-...@googlegroups.com
#31271: Logged queries may interpolate parameters in the wrong order on Oracle.
-------------------------------------+-------------------------------------
Reporter: Hans Aarne Liblik | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: oracle sql log | Triage Stage: Accepted
debug logging |
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/12465 PR]

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

Django

unread,
Feb 18, 2020, 5:45:25 AM2/18/20
to django-...@googlegroups.com
#31271: Logged queries may interpolate parameters in the wrong order on Oracle.
-------------------------------------+-------------------------------------
Reporter: Hans Aarne Liblik | Owner: felixxm
Type: Bug | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: oracle sql log | Triage Stage: Accepted
debug logging |
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:"2a038521c4eabdc5f6d5026d3dd6d22868e329cd" 2a038521]:
{{{
#!CommitTicketReference repository=""
revision="2a038521c4eabdc5f6d5026d3dd6d22868e329cd"
Fixed #31271 -- Preserved ordering when unifying query parameters on
Oracle.

This caused misplacing parameters in logged SQL queries.

Regression in 79065b55a70cd220820a260a1c54851b7be0615a.

Thanks Hans Aarne Liblik for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31271#comment:6>

Django

unread,
Feb 18, 2020, 5:46:56 AM2/18/20
to django-...@googlegroups.com
#31271: Logged queries may interpolate parameters in the wrong order on Oracle.
-------------------------------------+-------------------------------------
Reporter: Hans Aarne Liblik | Owner: felixxm
Type: Bug | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: oracle sql log | Triage Stage: Accepted
debug logging |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"2448b3182c75cce5d22dd80be0fb5cba6104c364" 2448b31]:
{{{
#!CommitTicketReference repository=""
revision="2448b3182c75cce5d22dd80be0fb5cba6104c364"
[3.0.x] Fixed #31271 -- Preserved ordering when unifying query parameters
on Oracle.

This caused misplacing parameters in logged SQL queries.

Regression in 79065b55a70cd220820a260a1c54851b7be0615a.

Thanks Hans Aarne Liblik for the report.

Backport of 2a038521c4eabdc5f6d5026d3dd6d22868e329cd from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31271#comment:7>

Reply all
Reply to author
Forward
0 new messages