[Django] #32734: django-admin startapp with trailing slash in directory name results in error

79 views
Skip to first unread message

Django

unread,
May 10, 2021, 9:13:02 AM5/10/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
--------------------------------------+------------------------
Reporter: jooadam | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
--------------------------------------+------------------------
Bash tab-completion appends trailing slashes to directory names. `django-
admin startapp name directory/` results in the error:

{{{CommandError: '' is not a valid app directory. Please make sure the
directory is a valid identifier.}}}

The error is caused by
[https://github.com/django/django/blob/main/django/core/management/templates.py#L77
line 77] of `django/core/management/templates.py` by calling `basename()`
on the path with no consideration for a trailing slash:

{{{#!python
self.validate_name(os.path.basename(target), 'directory')
}}}

Removing potential trailing slashes would solve the problem:

{{{#!python
self.validate_name(os.path.basename(target.rstrip(os.sep)), 'directory')
}}}

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

Django

unread,
May 11, 2021, 3:26:53 AM5/11/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+------------------------------------

Reporter: jooadam | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

OK, yes, this seems a case we could handle.

I didn't look into exactly why but it works for `startproject`:

{{{
$ django-admin startproject ticket32734 testing/
}}}

Thanks for the report. Do you fancy making a PR?

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

Django

unread,
May 11, 2021, 5:38:05 AM5/11/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+------------------------------------

Reporter: jooadam | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+------------------------------------

Comment (by Rohith P R):

> I didn't look into exactly why but it works for startproject

This is the relevant piece of code- should this same check be performed
for start project as well?

{{{
if app_or_project == 'app':
self.validate_name(os.path.basename(target), 'directory')
}}}

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

Django

unread,
May 11, 2021, 3:29:42 PM5/11/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+--------------------------------------
Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+--------------------------------------
Changes (by Rohith P R):

* owner: nobody => Rohith P R
* status: new => assigned


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

Django

unread,
May 11, 2021, 4:53:20 PM5/11/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+------------------------------------
Reporter: jooadam | Owner: jooadam
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2

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

* owner: Rohith P R => jooadam


Comment:

Replying to [comment:3 Rohith P R]:

Rohith, sorry for not assigning it to me first, I just submitted a pull
request: https://github.com/django/django/pull/14383

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:4>

Django

unread,
May 11, 2021, 5:54:16 PM5/11/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+------------------------------------
Reporter: jooadam | Owner: jooadam
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+------------------------------------

Comment (by Rohith P R):

Hey @jooadam! I already had a
[PR](https://github.com/django/django/pull/14382) open to fix this issue.
I left a comment on your PR btw. :)

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:5>

Django

unread,
May 11, 2021, 6:42:19 PM5/11/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+------------------------------------
Reporter: jooadam | Owner: jooadam
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+------------------------------------

Comment (by jooadam):

Replying to [comment:5 Rohith P R]:


> Hey @jooadam! I already had a
[PR](https://github.com/django/django/pull/14382) open to fix this issue.
I left a comment on your PR btw. :)

Yeah, I saw it after the fact :/

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:6>

Django

unread,
May 12, 2021, 1:31:31 AM5/12/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+--------------------------------------
Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2

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

* owner: jooadam => Rohith P R


--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:7>

Django

unread,
May 14, 2021, 2:07:47 AM5/14/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+--------------------------------------
Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
---------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


Comment:

Regression in fc9566d42daf28cdaa25a5db1b5ade253ceb064f.

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:8>

Django

unread,
May 14, 2021, 6:46:18 AM5/14/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+---------------------------------------------

Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

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

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:9>

Django

unread,
May 14, 2021, 2:36:02 PM5/14/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+---------------------------------------------
Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: closed
Component: Utilities | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+---------------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"530f58caaa5052e9e56bf8461caee4d821953bcb" 530f58ca]:
{{{
#!CommitTicketReference repository=""
revision="530f58caaa5052e9e56bf8461caee4d821953bcb"
Fixed #32734 -- Fixed validation of startapp's directory with trailing
slash.

Regression in fc9566d42daf28cdaa25a5db1b5ade253ceb064f.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:10>

Django

unread,
May 14, 2021, 4:34:49 PM5/14/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+---------------------------------------------
Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: closed
Component: Utilities | Version: 3.2

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+---------------------------------------------

Comment (by jooadam):

Replying to [comment:10 Mariusz Felisiak <felisiak.mariusz@…>]:

Mariusz, just wanted to say that I spent about four hours on my first
contribution to the project, that you just completely threw away here. I
probably won’t have a second.

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:11>

Django

unread,
May 14, 2021, 7:26:20 PM5/14/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+---------------------------------------------
Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: closed
Component: Utilities | Version: 3.2

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+---------------------------------------------

Comment (by Simon Charette):

jooadam, it's a shame that your contributing experience was not great and
to hear that your considering not repeating the experience but please be
fair to Mariusz here.

There was a miscommunication between multiple parties interested in
helping due to the lack of prior assignment of an owner and Mariusz has
little do to with that. I'm pretty sure Rohith also invested quite a lot
of time in getting his solution ready to address an an easy picking issue
and followed the contributing guidelines and in the end only a single
patch can land.

I sincerely hope you reconsider your decision that your realize these
hours were not completely thrown away as you've certainly learned a few
things about the contributing process along the way.

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:12>

Django

unread,
Aug 16, 2021, 10:05:57 AM8/16/21
to django-...@googlegroups.com
#32734: django-admin startapp with trailing slash in directory name results in
error
---------------------------+---------------------------------------------
Reporter: jooadam | Owner: Rohith P R
Type: Bug | Status: closed
Component: Utilities | Version: 3.2

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+---------------------------------------------

Comment (by dotuser):

Does any plan backport https://github.com/django/django/pull/11270 and
https://github.com/django/django/pull/14382 to branch stable/2.2.x and
stable/3.2.x.
{{{
# https://github.com/django/django/pull/11270
(base) root@69faeb96:/tmp/123321/django# git branch -a --contains
fc9566d42daf28cdaa25a5db1b5ade253ceb064f
* main
stable/3.2.x
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/make-zoneinfo-default-timezone-implementation
remotes/origin/stable/3.0.x
remotes/origin/stable/3.1.x
remotes/origin/stable/3.2.x

# https://github.com/django/django/pull/14382
(base) root@69faeb96-0f43-442b-ad2d-3e5cfa31f6d5:/tmp/123321/django# git
branch -a --contains 530f58caaa5052e9e56bf8461caee4d821953bcb
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/make-zoneinfo-default-timezone-implementation
}}}
Or, startapp will crash bug since PR
https://github.com/django/django/pull/11270:

{{{
(base) root@69faeb96:/tmp# /tmp/venv/bin/python -m django --version
3.2.6
(base) root@69faeb96:/tmp# /tmp/venv/bin/python -m django startproject
my_project -v3 && cd my_project
Rendering project template files with extensions: .py
Rendering project template files with filenames:
Creating /tmp/my_project/manage.py
Creating /tmp/my_project/my_project/__init__.py
Creating /tmp/my_project/my_project/asgi.py
Creating /tmp/my_project/my_project/settings.py
Creating /tmp/my_project/my_project/urls.py
Creating /tmp/my_project/my_project/wsgi.py

(base) root@69faeb96:/tmp/my_project# mkdir -p my_app && cd my_app
(base) root@69faeb96:/tmp/my_project/my_app# /tmp/venv/bin/python -m
django startapp my_app . -v3
CommandError: '.' is not a valid app directory. Please make sure the


directory is a valid identifier.
}}}

However, that's ok if startapp with other same method:
{{{
(base) root@69faeb96:/tmp/my_project/my_app# cd ..
(base) root@69faeb96:/tmp/my_project# ls
manage.py my_app my_project
(base) root@69faeb96:/tmp/my_project# rm -rf my_app/
(base) root@69faeb96:/tmp/my_project# ls
manage.py my_project
(base) root@69faeb96:/tmp/my_project# /tmp/venv/bin/python -m django
startapp my_app -v3
Rendering app template files with extensions: .py
Rendering app template files with filenames:
Creating /tmp/my_project/my_app/__init__.py
Creating /tmp/my_project/my_app/admin.py
Creating /tmp/my_project/my_app/apps.py
Creating /tmp/my_project/my_app/models.py
Creating /tmp/my_project/my_app/tests.py
Creating /tmp/my_project/my_app/views.py
Creating /tmp/my_project/my_app/migrations/__init__.py
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32734#comment:13>

Reply all
Reply to author
Forward
0 new messages