#36252: Duplicate Display of Imports in Django Shell
-------------------------------------+-------------------------------------
Reporter: Raffaella | Owner: hesham
| hatem
Type: Bug | Status: new
Component: Core (Management | Version: 5.2
commands) |
Severity: Release blocker | Resolution:
Keywords: shell | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):
* resolution: worksforme =>
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
* status: closed => new
Comment:
On a second look, I'm able to reproduce. I think the key difference is
having `isort` installed or not. Details:
* When building the `auto_imports` dict we are accumulating duplicating
modules (output reduced for easier reading):
{{{
(Pdb) pprint(auto_imports)
defaultdict(<class 'list'>, {
'django.contrib.admin.models': [('LogEntry',
<class
'django.contrib.admin.models.LogEntry'>)],
'django.contrib.auth.models': [('User',
<class
'django.contrib.auth.models.User'>),
('Group',
<class
'django.contrib.auth.models.Group'>),
('Permission',
<class
'django.contrib.auth.models.Permission'>)],
'django.contrib.contenttypes.models': [('ContentType',
<class
'django.contrib.contenttypes.models.ContentType'>)],
'django.contrib.sessions.models': [('Session',
<class
'django.contrib.sessions.models.Session'>)],
'django.urls': [('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>),
('reverse', <function reverse at
0x7d9628a5a700>)]})
}}}
* The above needs some cleanup, though the `namespace` dictionary items
are properly unique, see:
{{{
(Pdb) pprint(namespace)
{'ContentType': <class 'django.contrib.contenttypes.models.ContentType'>,
'Group': <class 'django.contrib.auth.models.Group'>,
'LogEntry': <class 'django.contrib.admin.models.LogEntry'>,
'Permission': <class 'django.contrib.auth.models.Permission'>,
'Session': <class 'django.contrib.sessions.models.Session'>,
'User': <class 'django.contrib.auth.models.User'>,
'reverse': <function reverse at 0x7d9628a5a700>}
}}}
* The resulting `import_string` has the duplicated entries, but later
`isort` would clean that up:
{{{
(Pdb) pprint(import_string)
(' from ticket_35928.models import TaggedItem, CollidingModelName, Image,
'
'Product, BlogPost, Comment\n'
' from testapp.models import UUIDModel, VulnerableModel, Course,
Student, '
'Ticket36031Model, CollidingModelName, BasicModel\n'
' from generatedapp.models import Review, AuthorProfile, BookGenre,
Genre, '
'Book, Author\n'
' from complexapp.models.c import ModelC\n'
' from complexapp.models.b import ModelB\n'
' from complexapp.models.a import ModelA\n'
' from abstractmodels.models import ArticlePage, Page\n'
' from django.contrib.sessions.models import Session\n'
' from django.contrib.contenttypes.models import ContentType\n'
' from django.contrib.auth.models import User, Group, Permission\n'
' from django.contrib.admin.models import LogEntry\n'
' from django.urls import reverse, reverse, reverse, reverse, reverse, '
'reverse, reverse, reverse, reverse')
}}}
Accepting since this should properly import and show unique entries, with
or without `isort`.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36252#comment:6>