Opened 4 years ago

Closed 4 years ago

Last modified 2 years ago

#31793 closed New feature (wontfix)

Async management command support

Reported by: James Pic Owned by: nobody
Component: Core (Management commands) Version: 3.0
Severity: Normal Keywords: assync
Cc: Jon Janzen Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, a management command with async def handle will fail for "coroutine was never awaited".

Change History (6)

comment:2 by Carlton Gibson, 4 years ago

Resolution: wontfix
Status: newclosed

Hi James.

Thanks for the suggestion. I'm going to say wontfix here: there's no need for async management commands. If a management command needs to run async code, for which, of course, there may be a need, asyncio.run() is the perfect approach. (I see you note that as the workaround on the PR.) It's just not worth any complexity to be able to handle top level async def handle methods directly. '

I hope that makes sense.

comment:3 by James Pic, 4 years ago

Well I'm not to judge if it makes sense, time & users will tell ;)

Version 0, edited 4 years ago by James Pic (next)

comment:4 by James Pic, 4 years ago

Just for the update: it seems both async and non async middlewares will be supported by Django: https://forum.djangoproject.com/t/the-trouble-with-middleware/19/11

So, if management commands would support both then it wouldn't be inconsistent.

comment:5 by Carlton Gibson, 4 years ago

Hi James. There's a fundamental difference between middlewares, which sit squarely on the request-response pathway, and need to be async capable if we're to leverage the full potential of that, on the one hand, and management commands, which are called one-by-one from the command line most usually, on the other. A management can use async code, in which can asyncio.run() is fine, but there's no demonstrated need for the top-level handle() entry point to itself be async capable. There's no concurrency need for management commands. ("Au contraire mon ami" -- fine, use multiprocessing if you insist, but there's nothing that's worth adding complexity to the main entry point here for.)

comment:6 by Jon Janzen, 2 years ago

Cc: Jon Janzen added
Note: See TracTickets for help on using tickets.
Back to Top