Opened 21 months ago
Closed 21 months ago
#34420 closed Cleanup/optimization (fixed)
Migration import ordering violates coding style and isort defaults
Reported by: | Andy Chosak | Owned by: | Andy Chosak |
---|---|---|---|
Component: | Migrations | Version: | 4.1 |
Severity: | Normal | Keywords: | migrations |
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
New migration files are generated with imports sorted by module, independent of import style. For example:
import datetime from django.db import migrations, models import time
The Django coding style specifies:
Place all
import
module statements beforefrom module import objects
in each section.
This guidance is the same as what isort does by default, as documented here. Newly generated migrations can fail isort for this reason.
This would mean migration files should instead be generated like this:
import datetime import time from django.db import migrations, models
For reference, previous issues related to migration import sorting: #24155, #25384.
Attachments (1)
Change History (6)
by , 21 months ago
Attachment: | patch.patch added |
---|
comment:1 by , 21 months ago
Has patch: | unset |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 21 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 21 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Normally I would reject this ticket as migrations are auto-generated code and it's not worth adding complicated logic to make them fully
isort
-compatible. However, this is a small tweak, so I'm happy to make it a slightly more accurate. Please send patch via a GitHub PR.