#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 before from 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)

patch.patch (1.7 KB ) - added by Andy Chosak 21 months ago.

Download all attachments as: .zip

Change History (6)

by Andy Chosak, 21 months ago

Attachment: patch.patch added

comment:1 by Mariusz Felisiak, 20 months ago

Has patch: unset
Triage Stage: UnreviewedAccepted

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.

comment:2 by Mariusz Felisiak, 20 months ago

Owner: changed from nobody to Andy Chosak
Status: newassigned

comment:3 by Andy Chosak, 20 months ago

Has patch: set

comment:4 by Mariusz Felisiak, 20 months ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 20 months ago

Resolution: fixed
Status: assignedclosed

In b295b311:

Fixed #34420 -- Corrected the order of imports in generated migration files.

Note: See TracTickets for help on using tickets.
Back to Top