﻿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
27170	Make database backend __init__() methods friendlier to subclassing	Chris Jerdonek	Chris Jerdonek	"The `__init__()` method for most or all of the database backends looks something like the following:

{{{#!python
def __init__(self, *args, **kwargs):
    super(DatabaseWrapper, self).__init__(*args, **kwargs)

    self.features = DatabaseFeatures(self)
    self.ops = DatabaseOperations(self)
    self.client = DatabaseClient(self)
    self.creation = DatabaseCreation(self)
    self.introspection = DatabaseIntrospection(self)
    self.validation = DatabaseValidation(self)
}}}

([https://github.com/django/django/blob/dbccf163b6e45bf2a673c249d4667360676acddc/django/db/backends/mysql/base.py#L231 Here] is a link to this code for the MySQL backend.)

Notice that each of the database classes is ""hard-coded.""

Since much of the behavior of the backends is defined by these classes (and so can be modified by changing these classes), it would be nice if it were easier to change what class is used. I believe this could be done simply by making each of these classes a class attribute.  This pattern is used to good effect, for example, throughout the test framework. You can see this being done in the definition of `DiscoverRunner`, for example, [https://github.com/django/django/blob/dbccf163b6e45bf2a673c249d4667360676acddc/django/test/runner.py#L388 here]:

{{{#!python
class DiscoverRunner(object):

    test_suite = unittest.TestSuite
    parallel_test_suite = ParallelTestSuite
    test_runner = unittest.TextTestRunner
    test_loader = unittest.defaultTestLoader
    reorder_by = (TestCase, SimpleTestCase)
}}}

"	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
