[Django] #30618: Fix wrong AppConfig.name when called startapp command with target

18 views
Skip to first unread message

Django

unread,
Jul 6, 2019, 10:07:14 AM7/6/19
to django-...@googlegroups.com
#30618: Fix wrong AppConfig.name when called startapp command with target
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
JungChaeMoon |
Type: | Status: assigned
Cleanup/optimization |
Component: Core | Version: master
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently, If someone calls the `startapp` command with a target directory
argument, the generated `AppConfig.name` is wrong.
It has to be a python path of app not just name of app.
So, users have to reset the attribute oneself.

In the document, 'AppConfig.name' is defined as follows.

{{{
AppConfig.name

Full Python path to the application, e.g. 'django.contrib.admin'.

This attribute defines which application the configuration applies to. It
must be set in all AppConfig subclasses.

It must be unique across a Django project.
}}}
[https://docs.djangoproject.com/en/2.2/ref/applications/#django.apps.AppConfig.name]

So, I belive that It has to be a path of app.

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

Django

unread,
Jul 8, 2019, 3:44:17 AM7/8/19
to django-...@googlegroups.com
#30618: AppConfig.name should be a full python path when using the optional
directory.
-------------------------------------+-------------------------------------
Reporter: JungChaeMoon | Owner:
| JungChaeMoon
Type: Bug | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

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

* owner: nobody => JungChaeMoon
* stage: Unreviewed => Accepted
* type: Cleanup/optimization => Bug
* needs_tests: 0 => 1


Comment:

[https://github.com/django/django/pull/11542 PR]

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

Django

unread,
Jul 9, 2019, 2:43:11 AM7/9/19
to django-...@googlegroups.com
#30618: AppConfig.name should be a full python path when using the optional
directory.
-------------------------------------+-------------------------------------
Reporter: JungChaeMoon | Owner:
| JungChaeMoon
Type: Bug | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


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

Django

unread,
Jul 16, 2019, 3:31:44 AM7/16/19
to django-...@googlegroups.com
#30618: AppConfig.name should be a full python path when using the optional
directory.
-------------------------------------+-------------------------------------
Reporter: JungChaeMoon | Owner:
| JungChaeMoon
Type: Bug | Status: closed

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

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


Comment:

I'm sorry, but I realized that we will not be able to handle all cases
properly and that this patch can cause regressions for people that call
`manage.py` for other directories, e.g.
{{{
python myproject/manage.py startapp test_app myproject/test_other_name
}}}
It is [https://docs.djangoproject.com/en/2.2/ref/django-admin/#startapp
documented] that `startapp` uses `app_name` as passed to the command and I
believe that we should keep this behavior. Thanks for your efforts!

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

Django

unread,
Aug 1, 2025, 4:30:34 AM8/1/25
to django-...@googlegroups.com
#30618: AppConfig.name should be a full python path when using the optional
directory.
-------------------------------------+-------------------------------------
Reporter: JungChaeMoon | Owner:
| JungChaeMoon
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David Sanders):

Felix, Sarah, Nessita, is this approach worth considering:

Someone requested this in the Django new-features repo (see point 2 on:
https://github.com/django/new-features/issues/62), so I reported it at
#36536 but Sarah pointed out this ticket.

I believe we can address this but using this approach:
- Use `settings.BASE_DIR` and `os.path.relpath()` to compare with the
supplied target directory (instead of using cwd)
- If `settings.BASE_DIR` was never specified (or removed as startproject
sets it) then simply use `app_name`
- If the relative path is outside `settings.BASE_DIR` then ignore it and
also revert to using `app_name`
- If within the project then convert to python path and use that instead.
--
Ticket URL: <https://code.djangoproject.com/ticket/30618#comment:4>

Django

unread,
Aug 1, 2025, 6:07:21 AM8/1/25
to django-...@googlegroups.com
#30618: AppConfig.name should be a full python path when using the optional
directory.
-------------------------------------+-------------------------------------
Reporter: JungChaeMoon | Owner:
| JungChaeMoon
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce):

I think one thing we would struggle with is custom templates for the
startapp command, as documented:
> The template context used for all matching files is:
> * Any option passed to the startapp command (among the command’s
supported options)
> * app_name – the app name as passed to the command

So you will either update app_name in the context to not be what it is
defined here, or you will add something new to the template context (and
existing templates may want to update their template).
Also in Mariusz's example, `python myproject/manage.py startapp test_app
myproject/test_other_name` I am not sure what the expected result would
be? To ignore the passed in app_name completely?
--
Ticket URL: <https://code.djangoproject.com/ticket/30618#comment:5>

Django

unread,
Aug 1, 2025, 6:26:25 AM8/1/25
to django-...@googlegroups.com
#30618: AppConfig.name should be a full python path when using the optional
directory.
-------------------------------------+-------------------------------------
Reporter: JungChaeMoon | Owner:
| JungChaeMoon
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David Sanders):

Ah yeah if you want to continue supporting supplied templates then I
suppose a new context variable `app_path` might be the go to avoid
breaking things.

I'm not sure whether Mariusz' example was demonstrating calling
`manage.py` from a different dir or having a different directory name
`test_other_name` (or both) but I think we could come up with a reasonable
result for both cases? 🤔
--
Ticket URL: <https://code.djangoproject.com/ticket/30618#comment:6>

Django

unread,
Aug 1, 2025, 7:24:57 AM8/1/25
to django-...@googlegroups.com
#30618: AppConfig.name should be a full python path when using the optional
directory.
-------------------------------------+-------------------------------------
Reporter: JungChaeMoon | Owner:
| JungChaeMoon
Type: Bug | Status: closed
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce):

So I guess each case just needs discussion and agreement. We have
identified things that would be potentially "breaking changes", so we need
an agreement of a path forward
The new features discussion (​https://github.com/django/new-
features/issues/62) might be the best place to build that proposal
--
Ticket URL: <https://code.djangoproject.com/ticket/30618#comment:7>
Reply all
Reply to author
Forward
0 new messages