Opened 11 years ago
Closed 11 years ago
#24514 closed Cleanup/optimization (fixed)
Unused import on some auto generated migrations
| Reported by: | Hugo Tácito | Owned by: | Chris Luc |
|---|---|---|---|
| Component: | Migrations | Version: | 1.7 |
| Severity: | Normal | Keywords: | unused import migrations |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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'},
),
]
Change History (7)
comment:1 by , 11 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 11 years ago
comment:4 by , 11 years ago
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
comment:5 by , 11 years ago
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.
comment:6 by , 11 years ago
| Has patch: | set |
|---|
I think
modelsis a convenience import and should stay around.