If a rollback or commit is attempted after the connection has failed
Django's BaseDatabaseWrapper does not know to check the validity of the
database connection and may fail due to the connection already being
closed. This is especially a problem when django is attempting to
automatically roll back transactions at the end of a request that has
already failed due to a database error and will result in the default
"Server Error" page being displayed as django cannot handle the error.
_cursor does not check if the connection is still valid, meaning that
once a connection has been marked as invalid it will attempt to get an
sqlalchemy cursor on a broken connection and throw an exception. This
commit causes the connection to be validated when using the cursor,
triggering a new connection to be fetched from the pool if the previous
one has been marked as dead.