[Django] #33378: django.core.exceptions.ImproperlyConfigured Error when installing apps in subdirectory

19 views
Skip to first unread message

Django

unread,
Dec 20, 2021, 9:37:38 AM12/20/21
to django-...@googlegroups.com
#33378: django.core.exceptions.ImproperlyConfigured Error when installing apps in
subdirectory
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
alphazwest |
Type: Bug | Status: new
Component: Core | Version: 4.0
(Other) | Keywords: Apps, Subdirectory,
Severity: Normal | Installation
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
4.0 Throws an exception when installing apps that are located in
subdirectories.

Example, for a project of such structure:


{{{
.
└── DjangoProject/
└── Apps/
├── bestapp/
│ ├── migrations
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
└── ...
}}}

When adding this line to DjangoProject/settings.py:


{{{
INSTALLED_APPS = [
...
'Apps.bestapp.apps.BestappConfig'
]
}}}

The following exception is thrown when running {{{python manage.py
makemigrations}}}:


{{{
django.core.exceptions.ImproperlyConfigured: Cannot import 'bestapp'.
Check that 'Apps.bestapp.apps.BestappConfig.name' is correct.

}}}

The current workaround is to go into the Apps/bestapp/apps.py file and
make the following change:


Auto-generated version:
{{{
class BestappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bestapp'
}}}

Manually-Updated version:
{{{
class BestappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Apps.bestapp'
}}}

Note the change being adding the parent directory here: {{{name =
'Apps.bestapp' }}}

IIRC, there was a syntax change for app installation somewhere in 3.x. Not
sure if this is a product of that change or something else.

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

Django

unread,
Dec 20, 2021, 2:07:49 PM12/20/21
to django-...@googlegroups.com
#33378: ImproperlyConfigured error is raised when installing apps in subdirectory
-------------------------------------+-------------------------------------
Reporter: Zack West | Owner: nobody
Type: Bug | Status: closed
Component: Core (Management | Version: 4.0
commands) |
Severity: Normal | Resolution: duplicate
Keywords: Apps, Subdirectory, | Triage Stage:
Installation | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate
* component: Core (Other) => Core (Management commands)


Comment:

Thanks for the report, however it works exactly the same in Django 3.2,
3.1, etc. I don't see any change in this behavior. `AppConfig.name` must
be a full Python path to the application, as
[https://docs.djangoproject.com/en/4.0/ref/applications/#django.apps.AppConfig.name
documented], so in your case `Apps.bestapp` is required and expected. We
tried to improve generated `apps.py` files in #30618 but it was clunky.

Duplicate of #30618.

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

Django

unread,
Jan 21, 2022, 12:05:43 PM1/21/22
to django-...@googlegroups.com
#33378: ImproperlyConfigured error is raised when installing apps in subdirectory
-------------------------------------+-------------------------------------

Reporter: Zack West | Owner: nobody
Type: Bug | Status: closed
Component: Core (Management | Version: 4.0
commands) |
Severity: Normal | Resolution: duplicate
Keywords: Apps, Subdirectory, | Triage Stage:
Installation | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Zack West):

Thanks and sorry for the duplicate post. It wasn't so much the requirement
of the full path I noted as much as it was Django *generating* a non-
fullpath when running the `python manage.py startapp` command or, more
particularly, if one is in a subdirectory (e.g. apps/) and runs the
command `django-admin startapp myapp` the `name` field in
`apps/myapp/apps.py` config class gets auto-populated with just `myapp`
rather than the required `apps.myapp` which will throw a
`django.core.exceptions.ImproperlyConfigured` exception unless a user
manually updates the `name` field.

I understand if that was passed over but I wanted to ensure I was drawing
attention to the proper aspect of the issue.

Replying to [comment:1 Mariusz Felisiak]:


> Thanks for the report, however it works exactly the same in Django 3.2,
3.1, etc. I don't see any change in this behavior. `AppConfig.name` must
be a full Python path to the application, as
[https://docs.djangoproject.com/en/4.0/ref/applications/#django.apps.AppConfig.name
documented], so in your case `Apps.bestapp` is required and expected. We
tried to improve generated `apps.py` files in #30618 but it was clunky.
>
> Duplicate of #30618.

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

Reply all
Reply to author
Forward
0 new messages