Opened 2 months ago

Closed 11 days ago

#36776 closed Cleanup/optimization (fixed)

Note that the dev server is running in WSGI mode

Reported by: Matthew Pava Owned by: jaffar Khan
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: jaffar Khan Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

With the mass adoption of async Django on the way, we need to provide a clearer warning in the development server that it is running in WSGI mode and not ASGI mode. I spent an hour troubleshooting a warning because I created a middleware that was async only. Only when I made it compatible for both async and sync modes did the warning go away.

Or we could just make the Django dev server default to ASGI mode.

Actual result:
The Django server displays this warning:
WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/6.0/howto/deployment/

Desired result:
Revise it to something like:
WARNING: This is a development server that is running only in sync mode (WSGI). Only middleware that is compatible with sync mode (WSGI) will run properly. Do not use it in a production setting. Use a production WSGI or ASGI server instead.

Change History (13)

comment:1 by Parvez Khan, 2 months ago

Owner: set to Parvez Khan
Status: newassigned

comment:2 by Jacob Walls, 2 months ago

Component: DocumentationCore (Management commands)
Triage Stage: UnreviewedAccepted
Version: 6.0dev

In general, this seems fine to tweak. I checked Daphne's runserver output, and it looks like:

Starting ASGI/Daphne version 4.2.1 development server at http://127.0.0.1:8000/

So I'd be happy to change Django's to:

  • django/core/management/commands/runserver.py

    diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
    index 0cf841b747..260badce5c 100644
    a b class Command(BaseCommand):  
    184184        print(
    185185            f"{now}\n"
    186186            f"Django version {version}, using settings {settings.SETTINGS_MODULE!r}\n"
    187             f"Starting development server at {self.protocol}://{addr}:{server_port}/\n"
     187            f"Starting WSGI development server at {self.protocol}://{addr}:{server_port}/\n"
    188188            f"Quit the server with {quit_command}.",
    189189            file=self.stdout,
    190190        )

However, mixing this information up with the security warning doesn't seem appropriate to me, nor taking a detour into middleware.

comment:3 by Matthew Pava, 2 months ago

That's fine. Can we also update the middleware documentation with some note that the development server only supports sync middleware?
https://docs.djangoproject.com/en/6.0/topics/http/middleware/

comment:4 by Jacob Walls, 2 months ago

Either there or on the async support page seems reasonable.

comment:5 by Clifford Gama, 2 months ago

Patch needs improvement: set

comment:6 by Nilesh Pahari, 7 weeks ago

Has patch: set

comment:7 by Nilesh Pahari, 7 weeks ago

Has patch: unset

comment:8 by Muhammed irshad ismail, 2 weeks ago

Hi, I’d like to work on this by adding a documentation note about the
development server running in WSGI (sync) mode, as suggested above.

comment:9 by jaffar Khan, 11 days ago

Cc: jaffar Khan added
Has patch: set

I create a PR on this Issue: https://github.com/django/django/pull/20588

Version 0, edited 11 days ago by jaffar Khan (next)

comment:10 by Mariusz Felisiak, 11 days ago

Owner: changed from Parvez Khan to jaffar Khan

comment:11 by Jacob Walls, 11 days ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:12 by Jacob Walls, 11 days ago

On second look I'm less convinced of the need to add anything in the middlewares section. If you're expecting async requests, you're using an async development server (perhaps the one from Daphne).

comment:13 by Jacob Walls <jacobtylerwalls@…>, 11 days ago

Resolution: fixed
Status: assignedclosed

In 2e83eb5e:

Fixed #36776 -- Clarified dev server runs in WSGI mode.

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