Opened 4 years ago

Closed 21 months ago

Last modified 21 months ago

#31626 closed New feature (wontfix)

Add asgi support to runserver

Reported by: Joshua Massover Owned by: nobody
Component: HTTP handling Version: 3.0
Severity: Normal Keywords: runserver, asgi
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Joshua Massover)

Previous conversation about this ticket can be found on the django forum

It would be great to add an asgi flag such that runserver will "just work" with ASGI. eg.

./manage.py runserver --asgi

The 4 options I've thought of are the following:

  1. Update runserver in django in a way that keeps the daphne import optional.
  2. Add daphne as a dependency to django and update runserver.
  3. Maintain a separate django app that holds the command that integrates daphne with runserver. Reference the app in asgi section of the django documentation.
  4. Add the commands to the daphne repository, perhaps allowing us to add daphne as an installed app so the command is discovered, and reference this in the asgi section of the django documentation.

I have an initial pr for (1). This code depends on #31594.

Change History (10)

comment:1 by Joshua Massover, 4 years ago

Description: modified (diff)

comment:2 by Carlton Gibson, 4 years ago

Resolution: needsinfo
Status: newclosed

I'm going to momentarily close this as needsinfo — let's continue the discussion on the forum thread: we can re-open if it's agreed to bundle this.

Yes, if runserver just worked would be good, but the draft PR is quite big, and doesn’t allow for other ASGI servers at all.

What’s the alternative? Install channels and add to INSTALLED_APPS. This is Option 3. This would allow an uvicorn-runserver option and so on. It’s not as neat but it might be a lot cleaner. :grimacing:

Last edited 4 years ago by Carlton Gibson (previous) (diff)

comment:3 by Carlton Gibson, 4 years ago

Component: UncategorizedHTTP handling
Keywords: runserver asgi added
Triage Stage: UnreviewedAccepted

OK, let's accept this as a new feature.

The suggestion in the forum thread is to detect if Daphne or uvicorn or ... is installed and then use that.

In the draft PR looks like importing Daphne in a try block, which I´m not sure about at all.
Is there a way we can detect the asgi server without hard-coding imports?

I'd imagined a server based off of Python's http.server, as we have for WSGI, either in Django or asigref as appropriate.

In the meantime, 3.1 could probably do with some docs, saying to install channels (to use it's runserver) or uvicorn (which has a --reload option).

comment:4 by Carlton Gibson, 4 years ago

Resolution: needsinfo
Status: closednew

comment:5 by Seth Michael Larson, 4 years ago

Hey! So I recently had a user hit this issue when using the recently added async support to the Elasticsearch client library.

See here: https://github.com/elastic/elasticsearch-py/issues/1303

comment:6 by Carlton Gibson, 21 months ago

Has patch: set

I've created a PR to doc that Daphne provided a runserver implementation. (PR)

You enable it like this:

    INSTALLED_APPS = [
        "daphne",
        ...
    ]

    ASGI_APPLICATION = "myproject.asgi.application"

Other packages could do similar easily enough.

I'm not 100% convinced it's worth extra code to scan installed dependencies, and check it they provide a runsever.

It could be that we close this as wontfix. 🤔

Last edited 21 months ago by Carlton Gibson (previous) (diff)

comment:7 by GitHub <noreply@…>, 21 months ago

In 279e611:

Refs #31626 -- Noted that Daphne provides a runserver command.

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 21 months ago

In d89d517:

[4.2.x] Refs #31626 -- Noted that Daphne provides a runserver command.

Backport of 279e611c017b5fcc055263e760de1495a9098ede from main

in reply to:  6 comment:9 by Mariusz Felisiak, 21 months ago

Resolution: wontfix
Status: newclosed

It could be that we close this as wontfix. 🤔

Let's close it.

comment:10 by Mariusz Felisiak, 21 months ago

Triage Stage: AcceptedUnreviewed
Note: See TracTickets for help on using tickets.
Back to Top