﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19274	Separate DB connection creation and session state initialization	Anssi Kääriäinen	nobody	"Currently when creating a new connection we create the connection and initialize it in one go (in _cursor()). Even if a backend splits getting a new connection and initializing the session variable this is not done consistently between backends.

The reason for this split is that this gives nice access point for external pooling implementations. A pool can wrap the backend and the methods ""get_new_connection()"" and ""close()"". Instead of actually creating new connections and closing the connection we can just get a connection from the pool and initialize the state of it. The real backend doesn't need to know anything about the pool wrapper.

The pool wrapper implementation would be something like this:
{{{
def get_new_connection():
    if pooled_connections_available():
        return connection from pool
    else:
        return super().get_new_connection()

def init_connection():
    do possible pool specific initialization
    super().init_connection()

def close():
    put the connection back to pool
}}}

I think this would allow connection pools for Django but with no need to implement them in core. In addition this should add readability of ._cursor() implementations."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
