[Django] #24514: Unused import on some auto generated migrations

8 views
Skip to first unread message

Django

unread,
Mar 20, 2015, 10:10:23 AM3/20/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Keywords: unused import
| migrations
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Some auto generated migrations don't use '''django.db.models'''.
Especially those that only change the Meta class. It would be nice to
change the '''django.db.migrations.writer.MIGRATION_TEMPLATE''' to only
add the '''from django.db import models''' if its really needed.

Example of auto generated migration with unused import:

{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('city', '0003_auto_20150305_0928'),
]

operations = [
migrations.AlterModelOptions(
name='city',
options={'verbose_name': 'City', 'verbose_name_plural':
'Cities'},
),
]

}}}

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

Django

unread,
Mar 20, 2015, 10:38:21 AM3/20/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: unused import | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


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

Django

unread,
Mar 21, 2015, 9:51:13 PM3/21/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: chrisjluc
Type: | Status: assigned

Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: unused import | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by chrisjluc):

* owner: nobody => chrisjluc
* status: new => assigned


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

Django

unread,
Mar 28, 2015, 2:34:13 PM3/28/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: chrisjluc
Type: | Status: assigned

Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: unused import | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by MarkusH):

I think `models` is a convenience import and should stay around.

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

Django

unread,
Apr 4, 2015, 7:40:17 PM4/4/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: chrisjluc
Type: | Status: assigned

Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: unused import | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by chrisjluc):

I think having `models` in a migration that doesn't use the import might
spark confusion for why it's being imported in the first place. I think it
makes the migrations cleaner by not having unused imports. I don't see
many situations where someone would manually need the `models` import.
But, in the rare occasion that they do need it, manually adding it is not
that bad. @MarkusH

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

Django

unread,
Apr 8, 2015, 9:59:32 AM4/8/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: chrisjluc
Type: | Status: assigned

Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: unused import | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by hugotacito):

Personally I'm having problems when I do automated code analysis with
pylint. I know this can be solved just ignoring the migrations folder but
it would be nice if django only do this import when necessary on auto
generated migrations.

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

Django

unread,
Apr 8, 2015, 12:16:35 PM4/8/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: chrisjluc
Type: | Status: assigned

Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: unused import | Triage Stage: Accepted
migrations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by chrisjluc):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:6>

Django

unread,
Apr 10, 2015, 7:09:21 AM4/10/15
to django-...@googlegroups.com
#24514: Unused import on some auto generated migrations
-------------------------------------+-------------------------------------
Reporter: hugotacito | Owner: chrisjluc
Type: | Status: closed

Cleanup/optimization |
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: unused import | Triage Stage: Accepted
migrations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"a7bc00e17bebe34cdf23f744937b3c386ee73d81" a7bc00e1]:
{{{
#!CommitTicketReference repository=""
revision="a7bc00e17bebe34cdf23f744937b3c386ee73d81"
Fixed #24514 -- Made migration writer omit models import if it's unused.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24514#comment:7>

Reply all
Reply to author
Forward
0 new messages