In the PR you propose to ping all database connections at the beginning and at the end of every HTTP request. I'm positive that this will have a significant performance impact. It's quite common to have secondary database connections that are rarely used, not scaled to be pinged twice per HTTP request, and sometimes slow to connect to.
I understand that you solved this problem in the context of Zalando. It's unclear to me that your solution easily generalizes to every Django-based system.
Surely, a serious, concrete proposal will be seriously considered. What we're missing at this point is a proposal that we can discuss!
As you know, currently, Django handles disconnects optimistically. It accepts to return one 500 error every time a worker loses its database connection. You can reduce this to one 500 error every time a worker loses its database connection while it's processing a request (rather than waiting for the next request) by disabling persistent connections with CONN_MAX_AGE = 0 but the performance hit is likely not worth the reliability improvement. On the ticket you say that you're seeing "a number of requests failing with 500s on every failover". Is that one request per thread or several requests in the same thread? The latter would be a bug.
You'd like to handle disconnects pessimistically. Since middleware runs outside of per-view transaction handling (when ATOMIC_REQUESTS is enabled), I think you can do anything you need in a middleware, which is likely what you have done (unless you had to patch Django?) A third-party package would be a good way to demonstrate the feature and also to document its pros and cons.
Best regards,