Opened 8 years ago
Closed 8 years ago
#27170 closed Cleanup/optimization (fixed)
Make database backend __init__() methods friendlier to subclassing
Reported by: | Chris Jerdonek | Owned by: | Chris Jerdonek |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The __init__()
method for most or all of the database backends looks something like the following:
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)
(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, here:
class DiscoverRunner(object): test_suite = unittest.TestSuite parallel_test_suite = ParallelTestSuite test_runner = unittest.TextTestRunner test_loader = unittest.defaultTestLoader reorder_by = (TestCase, SimpleTestCase)
Change History (6)
comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
comment:4 by , 8 years ago
Has patch: | set |
---|
comment:5 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I started working on this in this PR.