{{{#!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.
* Attachment "patch.patch" added.
* 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>
* owner: nobody => Andy Chosak
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/16662 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34420#comment:4>
* 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>