﻿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
24810	Reopen database connection automatically when no transaction is active	Aymeric Augustin	nobody	"This is a follow-up of #15802.

When the database closes the connection, for instance because the database server was restarted, an exception will be raised the next time user code attempts to use the database. Django doesn't attempt to do anything about it.

This is expected to result in at most one 500 error for each thread that serves requests, since database connections are thread-local. This doesn't sound horrific. After all the database was restarted while the website was serving requests.

It can also cause management commands to crash, which isn't the end of the world either since management commands should fall into one of the following categories:
- short-lived, idempotent and scheduled to run regularly
- long-lived and supervised to run constantly
- run manually

If the connection was in autocommit mode and an operation fails because the database has closed the connection, theoretically, it's safe the reopen the connection and retry the operation.

In that case, Django could continue to operate transparently instead of raising an exception.

This may not be easy to implement.

"	New feature	new	Database layer (models, ORM)	dev	Normal			depaolim@… binary@… Marti Raudsepp dms-cat amureki Kai Schlamp Ülgen Sarıkavak	Accepted	1	0	1	0	0	0
