#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.
--
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/058.ce2a782b7c6685d1a4c1d6e13b12b1a5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.