﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28203	assertNumQueries should ignore initial connection configuration queries	François Freitag	François Freitag	"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."	Bug	closed	Testing framework	dev	Normal	fixed	assertNumQueries		Accepted	1	0	0	0	0	0
