﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36424	Extend documentation related to handling of model name collisions in shell auto-imports	john-parton	SOHAIL AHMAD	"If you have two models with the same name, the automatic import logic will result in just one of them being imported.

{{{
$ ./manage.py shell -v2
116 objects imported automatically:

  from apps.order.models import Line, Order
  from apps.cart.models import Line, Cart

Python 3.13.3 (main, Apr  9 2025, 04:03:52) [Clang 20.1.0 ] on linux
Type ""help"", ""copyright"", ""credits"" or ""license"" for more information.
(InteractiveConsole)
>>> Line
<class 'apps.cart.models.Line'>
}}}

shell_plus has a few different ways to resolve this issue: https://django-extensions.readthedocs.io/en/latest/shell_plus.html#configuration

In my settings.py, I have the following


{{{
SHELL_PLUS_MODEL_ALIASES = {
    ""cart"": {""Line"": ""CartLine""},
    ""order"": {""Line"": ""OrderLine""},
}
}}}

To make matters even more annoying, if you have `isort` installed, the verbose output doesn't even match the expected behavior of the last import being the ultimately imported symbol.

Output with `isort`


{{{
$ ./manage.py shell -v2
116 objects imported automatically:

  from apps.cart.models import Cart, Line
  from apps.order.models import Line, Order

Python 3.13.3 (main, Apr  9 2025, 04:03:52) [Clang 20.1.0 ] on linux
Type ""help"", ""copyright"", ""credits"" or ""license"" for more information.
(InteractiveConsole)
>>> Line
<class 'apps.cart.models.Line'>
}}}


Note that you do not get a warning even if you run python with `-Wall`

I'm inclined to say that the behavior as-is could be considered a bug. From the perspective of the user, there's no explicable reason why one model is picked over the other and there's no indication that such an overwrite took place. However, this is basically the same behavior as shell_plus, so perhaps that's being too harsh with django.

Some possible fixes:

1. Document the behavior, maybe here: https://docs.djangoproject.com/en/5.2/howto/custom-shell/ ; and/or
2. Emit a warning in this case; and/or
3. Don't import either model

Alternatively, implement user configurable ""import as"" or aliases, although that's outside the scope of a bugfix and into feature territory."	Cleanup/optimization	assigned	Core (Management commands)	5.2	Normal			Salvo Polizzi Adam Johnson Bhuvnesh	Accepted	1	0	0	1	0	0
