Report DatabaseOperationalError as an HTTP Service Unavailable error
Closes #12736
This commit is contained in:
@@ -24,6 +24,7 @@ except ImportError:
|
||||
PYDATE, PYDATETIME, PYTIME, PYINTERVAL = None, None, None, None
|
||||
from psycopg2 import DataError as DatabaseDataError
|
||||
from psycopg2 import IntegrityError as DatabaseIntegrityError
|
||||
from psycopg2 import InterfaceError
|
||||
from psycopg2 import OperationalError as DatabaseOperationalError
|
||||
from psycopg2 import ProgrammingError
|
||||
from psycopg2.errors import QueryCanceled as DatabaseTimeoutError
|
||||
@@ -291,7 +292,10 @@ class Database(DatabaseInterface):
|
||||
return conn
|
||||
|
||||
def put_connection(self, connection, close=False):
|
||||
connection.reset()
|
||||
try:
|
||||
connection.reset()
|
||||
except InterfaceError:
|
||||
pass
|
||||
self._connpool.putconn(connection, close=close)
|
||||
|
||||
def close(self):
|
||||
|
||||
@@ -238,8 +238,9 @@ class Transaction(object):
|
||||
else:
|
||||
self.rollback()
|
||||
finally:
|
||||
self.database.put_connection(
|
||||
self.connection, self.close)
|
||||
if self.connection:
|
||||
self.database.put_connection(
|
||||
self.connection, self.close)
|
||||
finally:
|
||||
self.database = None
|
||||
self.readonly = False
|
||||
@@ -357,7 +358,8 @@ class Transaction(object):
|
||||
datamanager.tpc_abort(self)
|
||||
Cache.rollback(self)
|
||||
self._clear_log_records()
|
||||
self.connection.rollback()
|
||||
if self.connection:
|
||||
self.connection.rollback()
|
||||
|
||||
def join(self, datamanager):
|
||||
try:
|
||||
|
||||
@@ -26,6 +26,7 @@ try:
|
||||
except ImportError:
|
||||
from werkzeug.wsgi import SharedDataMiddleware
|
||||
|
||||
from trytond import backend
|
||||
from trytond.config import config
|
||||
from trytond.protocols.jsonrpc import JSONProtocol
|
||||
from trytond.protocols.wrappers import (
|
||||
@@ -111,6 +112,10 @@ class TrytondWSGI(object):
|
||||
logger.debug(
|
||||
"Exception when processing %s", request, exc_info=True)
|
||||
return e
|
||||
except backend.DatabaseOperationalError as e:
|
||||
logger.debug(
|
||||
"Exception when processing %s", request, exc_info=True)
|
||||
return exceptions.ServiceUnavailable(description=str(e))
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
"Exception when processing %s", request, exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user