#27170: Make database backend __init__() methods friendlier to subclassing ----------------------------------------------+-------------------- Reporter: cjerdonek | Owner: nobody Type: Uncategorized | Status: new Component: Database layer (models, ORM) | Version: master Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+-------------------- 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) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/27170> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.3f469ae7b7bac74d3f5a5ee5ec056e7d%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.