Opened 5 years ago
Closed 4 years ago
#32317 closed Cleanup/optimization (fixed)
Clean up loaddata
| Reported by: | William Schwartz | Owned by: | William Schwartz |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev |
| Severity: | Normal | Keywords: | loaddata |
| 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 (last modified by )
In django.core.management.commands.Command, load_label is 66 lines long with maximum indentation of 9 levels (the row starts at column 37). find_fixtures is 56 lines. These monolith methods are hard to read, hard to override, and, in some places, violate PEP-8's recommendation to keep try blocks small.
The reason I care about this is that an app I'm working on may need to customize how loaddata finds fixtures, and, unlike templates, there isn't a nice loader API to hook into. So that leaves me with overriding find_fixtures. My initial attempt was a mess because of how giant the parent class's method is.
I am submitting PR GH-13842 with my proposed refactoring. The commits will need to be squashed before merging the PR, but I wanted to include commit message to justify some of the less obvious-looking changes.
Change History (8)
comment:1 by , 5 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 5 years ago
| Has patch: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:4 by , 4 years ago
| Patch needs improvement: | set |
|---|
comment:7 by , 4 years ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Looks good to me, awesome work!