[Django] #34420: Migration import ordering violates coding style and isort defaults

2 views
Skip to first unread message

Django

unread,
Mar 17, 2023, 12:59:49 PM3/17/23
to django-...@googlegroups.com
#34420: Migration import ordering violates coding style and isort defaults
-------------------------------------+-------------------------------------
Reporter: Andy | Owner: nobody
Chosak |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 4.1
Migrations |
Severity: Normal | Keywords: migrations
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
New migration files are generated with imports sorted by module,
independent of import style. For example:

{{{#!python
import datetime
from django.db import migrations, models
import time
}}}

The [[https://docs.djangoproject.com/en/dev/internals/contributing
/writing-code/coding-style/#imports|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,
[[https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html
#controlling-how-isort-sections-from-imports|as documented here]]. Newly
generated migrations can fail isort for this reason.

This would mean migration files should instead be generated like this:

{{{#!python
import datetime
import time
from django.db import migrations, models
}}}

For reference, previous issues related to migration import sorting:
#24155, #25384.

--
Ticket URL: <https://code.djangoproject.com/ticket/34420>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 17, 2023, 12:59:50 PM3/17/23
to django-...@googlegroups.com
#34420: Migration import ordering violates coding style and isort defaults
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Migrations | Version: 4.1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Andy Chosak):

* Attachment "patch.patch" added.

Django

unread,
Mar 18, 2023, 8:53:00 AM3/18/23
to django-...@googlegroups.com
#34420: Migration import ordering violates coding style and isort defaults
--------------------------------------+------------------------------------

Reporter: Andy Chosak | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Migrations | Version: 4.1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 1 => 0
* stage: Unreviewed => Accepted


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:1>

Django

unread,
Mar 18, 2023, 8:53:17 AM3/18/23
to django-...@googlegroups.com
#34420: Migration import ordering violates coding style and isort defaults
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Andy
Type: | Chosak
Cleanup/optimization | Status: assigned

Component: Migrations | Version: 4.1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Andy Chosak
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:2>

Django

unread,
Mar 18, 2023, 2:08:21 PM3/18/23
to django-...@googlegroups.com
#34420: Migration import ordering violates coding style and isort defaults
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Andy
Type: | Chosak
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 4.1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Andy Chosak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/16662 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:3>

Django

unread,
Mar 20, 2023, 1:24:05 AM3/20/23
to django-...@googlegroups.com
#34420: Migration import ordering violates coding style and isort defaults
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Andy
Type: | Chosak
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 4.1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:4>

Django

unread,
Mar 20, 2023, 2:58:04 AM3/20/23
to django-...@googlegroups.com
#34420: Migration import ordering violates coding style and isort defaults
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Andy
Type: | Chosak
Cleanup/optimization | Status: closed
Component: Migrations | Version: 4.1
Severity: Normal | Resolution: fixed

Keywords: migrations | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"b295b311712b598c053f7fa8cf6e6882217e35d9" b295b311]:
{{{
#!CommitTicketReference repository=""
revision="b295b311712b598c053f7fa8cf6e6882217e35d9"
Fixed #34420 -- Corrected the order of imports in generated migration
files.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:5>

Reply all
Reply to author
Forward
0 new messages