Skip to content

v0.5.0 — Django middleware overhaul

Choose a tag to compare

@heysamtexas heysamtexas released this 11 Jun 01:53
· 2 commits to main since this release
45d4f82

Overhauls the Django RequestLoggingMiddleware: correct user attribution for email-auth services, native async support, accurate streaming durations, and a request log on the exception path. Bundles #34, #40, and #41.

uv add "git+https://github.com/collide-ai/collide-logging-py.git@v0.5.0"

Fixed

  • user: null for email-auth users (#34). The middleware read user.username, which is None on models with USERNAME_FIELD = "email". It now reads user.get_username(), correct for both default-username and email-auth models.
  • duration_ms measured at stream open for streaming responses (#41). The http.request line is now deferred by hooking response.close(), so duration_ms reflects time to stream close. Covers WSGI (incl. abandonment, per PEP 3333), ASGI normal completion, and errors.
  • Unhandled handler exceptions produced no request log (#41). A status-500 line with the traceback is now emitted before the exception propagates (guarded so a throwing request.user can't mask the real error).

Added

  • RequestLoggingMiddleware is now async-capable (#40). Declares sync_capable/async_capable, detects an async get_response, and awaits it on a coroutine path — no sync/async adaptation boundary on ASGI stacks. Sync deployments unchanged.

Known limitation

  • On ASGI, a client disconnect mid-stream cancels the request task without calling response.close() (Django's ASGIHandler), so that one case is not logged (#42). All WSGI, all non-streaming, and ASGI streams that complete normally or error are covered.

Compatibility

  • django>=5. All APIs used are available on Django 5.0+; CI exercises the resolved Django (6.0.4) only.

Full prior history: v0.4.1 (validate-mode fail-safe), v0.4.0 (events API safety) — see CHANGELOG.