[Django] #28203: assertNumQueries should ignore initial connection configuration queries

9 views
Skip to first unread message

Django

unread,
May 12, 2017, 10:55:26 PM5/12/17
to django-...@googlegroups.com
#28203: assertNumQueries should ignore initial connection configuration queries
-------------------------------------+-------------------------------------
Reporter: François | Owner: nobody
Freitag |
Type: Bug | Status: new
Component: Testing | Version: master
framework |
Severity: Normal | Keywords: assertNumQueries
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Upon connection to the database, Django may trigger queries to configure
the connection state (e.g.
[https://github.com/django/django/blob/master/django/db/backends/mysql/base.py#L254
MySQL transaction isolation and AUTO_IS_NULL],
[https://github.com/django/django/blob/master/django/db/backends/oracle/base.py#L210-L219
oracle dates format],
[https://github.com/django/django/blob/master/django/db/backends/postgresql/base.py#L193
postgresql timezones]).
IMHO, these queries should be ignored by {{{assertNumQueries}}}.

My use case, on MySQL 5.5.54-0 and MariaDB 10.1.23-1:
{{{#!python
from django.contrib.contenttypes.models import ContentType
from django.test import TransactionTestCase


class MyTests(TransactionTestCase):

available_apps = []

def test_assertNumQueries_counts_db_configuration_queries(self):
# Emulates connection being closed after previous query/test
# possibly because the connection expired (e.g. CONN_MAX_AGE=0)
connection.close()

with self.assertNumQueries(1):
list(ContentType.objects.all())

# Fails with:
# AssertionError: 2 != 1 : 2 queries executed, 1 expected
# Captured queries were:
# SET TX_ISOLATION = 'read-committed'
# SELECT `django_content_type`.`id`,
`django_content_type`.`app_label`, `django_content_type`.`model` FROM
`django_content_type`

}}}

Thanks to Cole Maclean for the initial report.

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

Django

unread,
May 13, 2017, 8:15:36 PM5/13/17
to django-...@googlegroups.com
#28203: assertNumQueries should ignore initial connection configuration queries
-----------------------------------+------------------------------------
Reporter: François Freitag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: assertNumQueries | 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


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

Django

unread,
May 13, 2017, 9:58:11 PM5/13/17
to django-...@googlegroups.com
#28203: assertNumQueries should ignore initial connection configuration queries
-------------------------------------+-------------------------------------
Reporter: François Freitag | Owner: François
| Freitag
Type: Bug | Status: assigned

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: assertNumQueries | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by François Freitag):

* owner: nobody => François Freitag
* status: new => assigned


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

Django

unread,
May 14, 2017, 4:04:40 PM5/14/17
to django-...@googlegroups.com
#28203: assertNumQueries should ignore initial connection configuration queries
-------------------------------------+-------------------------------------
Reporter: François Freitag | Owner: François
| Freitag
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: assertNumQueries | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by François Freitag):

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
May 18, 2017, 12:09:06 PM5/18/17
to django-...@googlegroups.com
#28203: assertNumQueries should ignore initial connection configuration queries
-------------------------------------+-------------------------------------
Reporter: François Freitag | Owner: François
| Freitag
Type: Bug | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed

Keywords: assertNumQueries | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"98b3b14a648a128d409b8f6169c1a4ff9d71c1a4" 98b3b14a]:
{{{
#!CommitTicketReference repository=""
revision="98b3b14a648a128d409b8f6169c1a4ff9d71c1a4"
Fixed #28203 -- Ignored connection configuration queries in
assertNumQueries().
}}}

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

Reply all
Reply to author
Forward
0 new messages