[Django] #27254: Detect management command context

10 views
Skip to first unread message

Django

unread,
Sep 20, 2016, 11:42:46 AM9/20/16
to django-...@googlegroups.com
#27254: Detect management command context
-------------------------------+--------------------
Reporter: beruic | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I have some code in my project that generates some content for my pages
(compiles documentation).

I would like this code to run once every time the server starts, and
essentially I should use `AppConfig.ready()` to do this. However
`AppConfig.ready()` also runs when I run any management command, which is
very undesirrable, as I don't want to generate this content every time I
run unrelated tasks, such as `migrate`.

Therefore it would be nice to have a flag or some other means to detect if
code is currently running in the context a web server or not.

For now I have implemented this as a middleware which throws
`MiddlewareNotUsed` after generating the content.

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

Django

unread,
Sep 20, 2016, 12:08:32 PM9/20/16
to django-...@googlegroups.com
#27254: Detect management command context
-------------------------------+--------------------------------------

Reporter: beruic | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

What about putting the code to be run when the server starts in `wsgi.py`?
I'm not so sure if the prosed "context" idea is feasible.

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

Django

unread,
Sep 21, 2016, 3:08:29 AM9/21/16
to django-...@googlegroups.com
#27254: Detect web server command context
------------------------------------+--------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody

Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

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

Django

unread,
Sep 21, 2016, 3:10:18 AM9/21/16
to django-...@googlegroups.com
#27254: Detect web server command context
------------------------------------+--------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody

Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Jimmy Merrild Krag):

But what if the project is not served through wsgi?

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

Django

unread,
Sep 21, 2016, 5:45:29 AM9/21/16
to django-...@googlegroups.com
#27254: Detect web server context
------------------------------------+--------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody

Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

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

Django

unread,
Sep 21, 2016, 6:32:35 AM9/21/16
to django-...@googlegroups.com
#27254: Detect web server context
------------------------------------+--------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody

Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Tim Graham):

How else do you run a project?

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

Django

unread,
Sep 21, 2016, 7:31:14 AM9/21/16
to django-...@googlegroups.com
#27254: Detect web server context
------------------------------------+--------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody

Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Aymeric Augustin):

AFAIK the three supported ways to use Django are:

1. running a WSGI server with the documented WSGI API
2. running management commands with django-admin (or manage.py)
3. `django.setup(); do_stuff()`

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

Django

unread,
Sep 21, 2016, 10:40:02 AM9/21/16
to django-...@googlegroups.com
#27254: Detect web server context
------------------------------------+--------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody

Type: New feature | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Jimmy Merrild Krag):

`python manage.py runserver` during development, but you make a valid
point. Need to test if I can run my things there then, and then i guess
developers must just run a management command manually to build
documentation.

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

Django

unread,
Sep 21, 2016, 10:42:21 AM9/21/16
to django-...@googlegroups.com
#27254: Detect web server context
------------------------------------+--------------------------------------
Reporter: Jimmy Merrild Krag | Owner: nobody
Type: New feature | Status: closed
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by Jimmy Merrild Krag):

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


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

Reply all
Reply to author
Forward
0 new messages