[Django] #33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS'] in settings

4 views
Skip to first unread message

Django

unread,
Jan 29, 2022, 5:37:13 PM1/29/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
-----------------------------------------+-----------------------------
Reporter: craiglabenz | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Keywords: development
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-----------------------------
Repro steps:

$ pip install -U django
$ django-admin startproject <name>

Open settings.py, copy the BASE_DIR variable from line 16 and paste it
into the empty DIRS list on line 57

$ ./manage.py runserver

Back in your IDE, save a file and watch the dev server *NOT* restart.

Back in settings.py, remove BASE_DIR from the templates DIRS list.
Manually CTRL-C your dev server (as it won't restart on its own when you
save), restart the dev server. Now return to your settings.py file, re-
save it, and notice the development server once again detects changes and
restarts.

This bug prevents the dev server from restarting no matter where you make
changes - it is not just scoped to edits to settings.py.

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

Django

unread,
Jan 30, 2022, 2:00:02 AM1/30/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
-------------------------------+--------------------------------------

Reporter: craiglabenz | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:

Keywords: development | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Hrushikesh Vaidya):

I don't think this is a bug, really. Adding `BASE_DIR` to the list of
template directories causes the entire project directory
to be marked as a template directory, and Django does not watch for
changes in template directories by design.

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

Django

unread,
Jan 30, 2022, 5:20:54 AM1/30/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
-------------------------------+--------------------------------------

Reporter: craiglabenz | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:

Keywords: development | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Keryn Knight):

* cc: Keryn Knight (added)


Comment:

I ''think'' I encountered this recently while making examples for #33461,
though I didn't get fully to the bottom of what was going on.

> Django does not watch for changes in template directories by design.

It does, via the `template_changed` signal listener, which from my brief
poking around when I saw it, is I believe the one which prevented
`trigger_reload` from executing. But that mostly led to my realising I
don't know what function is responsible for reloading for python files,
rather than template/i18n files, so I moved on.

I would ''tentatively'' accept this, personally.

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

Django

unread,
Jan 30, 2022, 10:29:44 PM1/30/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
-------------------------------+--------------------------------------

Reporter: craiglabenz | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:

Keywords: development | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Hrushikesh Vaidya):

* cc: Hrushikesh Vaidya (added)


Comment:

Replying to [comment:2 Keryn Knight]:

> > Django does not watch for changes in template directories by design.
> It does, via the `template_changed` signal listener

My bad, I meant that Django does not watch for changes in template
directories to ''reload the server''. The `template_changed` signal
listener returns `True` if the change occurs in a file located in a
designated template directory, which causes `notify_file_changed` to not
trigger the reload.

AFAIK from browsing the code, for a python file (or actually any file not
in a template directory), the `template_changed` signal listener returns
`None`, which causes `notify_file_changed` to trigger the reload, right?

So could we fix this by checking if the changed file is a python file
inside the `template_changed` signal listener, regardless of whether it is
in a template directory?

{{{
def template_changed(sender, file_path, **kwargs):
if file_path.suffix == '.py':
return
# Now check if the file was a template file
}}}

This seems to work on a test project, but I have not checked for side
effects, although I don't think there should be any.

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

Django

unread,
Feb 2, 2022, 10:11:23 AM2/2/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
--------------------------------------+------------------------------------
Reporter: craiglabenz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 4.0
Severity: Normal | Resolution:
Keywords: development | Triage Stage: Accepted

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

* cc: Tom Forbes (added)
* type: Bug => Cleanup/optimization
* component: Uncategorized => Core (Other)
* stage: Unreviewed => Accepted


Comment:

> I would ''tentatively'' accept this, personally.

😀 I was thinking I'd ''tentatively'' `wontfix`, as not worth the
complication — but let's accept for review and see what the consensus is.

Hrushikesh, would you like to prepare a PR based on your suggestion?

Thanks!

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

Django

unread,
Feb 2, 2022, 12:16:17 PM2/2/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
--------------------------------------+------------------------------------
Reporter: craiglabenz | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 4.0
Severity: Normal | Resolution:
Keywords: development | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Hrushikesh Vaidya):

Sure! [https://github.com/django/django/pull/15388 PR]

At first I thought keeping python files in a template directory does not
seem so intuitive, at least to me, same with marking a more general
purpose directory as a template directory. But I guess if someone does
want to do it that way, it would be nice to support autoreload in that
scenario as well.

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

Django

unread,
Feb 2, 2022, 12:26:06 PM2/2/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
-------------------------------------+-------------------------------------
Reporter: craiglabenz | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned

Component: Core (Other) | Version: 4.0
Severity: Normal | Resolution:
Keywords: development | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* owner: nobody => Hrushikesh Vaidya
* status: new => assigned
* has_patch: 0 => 1


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

Django

unread,
Feb 3, 2022, 4:38:30 AM2/3/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
-------------------------------------+-------------------------------------
Reporter: craiglabenz | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: 4.0
Severity: Normal | Resolution:
Keywords: development | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Feb 3, 2022, 6:53:30 AM2/3/22
to django-...@googlegroups.com
#33473: Dev Server fails to restart after adding BASE_DIR to TEMPLATES[0]['DIRS']
in settings
-------------------------------------+-------------------------------------
Reporter: craiglabenz | Owner:
Type: | Hrushikesh Vaidya
Cleanup/optimization | Status: closed

Component: Core (Other) | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: development | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"832adb31f27cfc18ad7542c7eda5a1b6ed5f1669" 832adb31]:
{{{
#!CommitTicketReference repository=""
revision="832adb31f27cfc18ad7542c7eda5a1b6ed5f1669"
Fixed #33473 -- Fixed detecting changes by autoreloader in .py files
inside template directories.
}}}

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

Reply all
Reply to author
Forward
0 new messages