Opened 10 months ago
Closed 10 months ago
#35107 closed Cleanup/optimization (wontfix)
How to write a management command that reads from stdin should be documented
Reported by: | Andrew Northall | Owned by: | Richard Zhao |
---|---|---|---|
Component: | Documentation | Version: | 5.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This seems like a fairly common use case, which is supported by Django, but as far as I can tell no mention of it is made in the documentation. It seems like it should be documented.
For an example of how to do it, loaddata
and shell
read from stdin in Django core:
https://github.com/django/django/blob/main/django/core/management/commands/loaddata.py
https://github.com/django/django/blob/main/django/core/management/commands/shell.py
I hear you say, 'but reading from stdin is a Python feature, not a Django feature, why should we document it?'. In my mind, the documentation as it exists now could lead to confusion: it makes specific mention that you should use BaseCommand.stdout
and BaseCommand.stderr
within a management command to write to stdout or stderr. It is not a big jump to then assume that you should also be using BaseCommand.stdin
(which does not exist) to handle incoming data. The API, in this narrow sense, is inconsistent, and this is why the documentation would be helpful.
Change History (2)
comment:1 by , 10 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 10 months ago
Easy pickings: | unset |
---|---|
Resolution: | → wontfix |
Status: | assigned → closed |
Type: | Uncategorized → Cleanup/optimization |
Replying to Andrew Northall:
Thanks for the ticket, however, we cannot document everything.
I don't see anything inconsistency in API or docs. We don't document nonexistent attributes, and users cannot assume that attributes exist if they are not documented. In management commands you can use
sys.stdin
like everywhere else, there is nothing specific that they provide. You can start a discussion on DevelopersMailingList if you don't agree.