﻿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
27074	connection.is_usable() raises AttributeError after the connection is closed	Chris Jerdonek		"I know a [https://code.djangoproject.com/ticket/26282 similar issue] was closed relatively recently as won't fix, but I wanted to report a more obvious example of the same issue just to be sure.

The following test case--

{{{#!python
from django.db import connection
from django.test import TransactionTestCase

class MyTest(TransactionTestCase):

    def test_connection_close(self):
        self.assertTrue(connection.is_usable())
        connection.close()
        self.assertFalse(connection.is_usable())
}}}

results in the following error (though if `TransactionTestCase` is replaced by `TestCase`, it would behave as expected)--

{{{#!python
Traceback (most recent call last):
  ...
  File "".../test_database.py"", line 23, in test_connection_close
    self.assertTrue(connection.is_usable())
  File "".../site-packages/django/db/backends/postgresql/base.py"", line 229, in is_usable
    self.connection.cursor().execute(""SELECT 1"")
AttributeError: 'NoneType' object has no attribute 'cursor'
}}}

Would there be any harm in handling the case of `self.connection` being `None` (e.g. using EAFP)?  It seems like this could even be done so the logic is only in the base class.
"	Cleanup/optimization	new	Database layer (models, ORM)	1.10	Normal			boblefrag@…	Accepted	0	0	0	0	0	0
