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.
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28203#comment:1>
* owner: nobody => François Freitag
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28203#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/8503 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28203#comment:3>
* 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>