v0.5.0 — Django middleware overhaul
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: nullfor email-auth users (#34). The middleware readuser.username, which isNoneon models withUSERNAME_FIELD = "email". It now readsuser.get_username(), correct for both default-username and email-auth models.duration_msmeasured at stream open for streaming responses (#41). Thehttp.requestline is now deferred by hookingresponse.close(), soduration_msreflects 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.usercan't mask the real error).
Added
RequestLoggingMiddlewareis now async-capable (#40). Declaressync_capable/async_capable, detects an asyncget_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.