fix: rollback transaction on sanitize_context_cids failure to prevent InFailedSqlTransaction state
This commit is contained in:
parent
afbcb4d052
commit
c7189ebe91
@ -33,7 +33,10 @@ class IrHttp(models.AbstractModel):
|
||||
if not valid_cids:
|
||||
valid_cids = [default_cid]
|
||||
if valid_cids != cids:
|
||||
_logger.warning("Sanitized allowed_company_ids in context from %s to %s for user %s", cids, valid_cids, request.env.uid)
|
||||
_logger.warning(
|
||||
"Sanitized allowed_company_ids in context from %s to %s for user %s",
|
||||
cids, valid_cids, request.env.uid,
|
||||
)
|
||||
context['allowed_company_ids'] = valid_cids
|
||||
return True
|
||||
return False
|
||||
@ -59,8 +62,19 @@ class IrHttp(models.AbstractModel):
|
||||
kwargs_context = kwargs.get('context')
|
||||
if isinstance(kwargs_context, dict):
|
||||
sanitize_context_cids(kwargs_context, user_cids, default_cid)
|
||||
|
||||
except Exception as e:
|
||||
_logger.warning("IrHttp: could not sanitize company context in _pre_dispatch: %s", e, exc_info=True)
|
||||
_logger.warning(
|
||||
"IrHttp: could not sanitize company context in _pre_dispatch: %s", e,
|
||||
)
|
||||
# Roll back the aborted transaction so subsequent DB queries in this
|
||||
# request can still execute. Without this PostgreSQL keeps the
|
||||
# connection in an InFailedSqlTransaction state and rejects every
|
||||
# further query in the same request.
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return super()._pre_dispatch(rule, args)
|
||||
|
||||
@ -87,7 +101,10 @@ class IrHttp(models.AbstractModel):
|
||||
if not valid_cids:
|
||||
valid_cids = [default_cid]
|
||||
if valid_cids != cids:
|
||||
_logger.warning("Sanitized allowed_company_ids in _dispatch from %s to %s for user %s", cids, valid_cids, request.env.uid)
|
||||
_logger.warning(
|
||||
"Sanitized allowed_company_ids in _dispatch from %s to %s for user %s",
|
||||
cids, valid_cids, request.env.uid,
|
||||
)
|
||||
context['allowed_company_ids'] = valid_cids
|
||||
return True
|
||||
return False
|
||||
@ -104,7 +121,18 @@ class IrHttp(models.AbstractModel):
|
||||
kwargs_context = kwargs.get('context')
|
||||
if isinstance(kwargs_context, dict):
|
||||
sanitize_context_cids(kwargs_context, user_cids, default_cid)
|
||||
|
||||
except Exception as e:
|
||||
_logger.warning("IrHttp: could not sanitize company context in _dispatch: %s", e, exc_info=True)
|
||||
_logger.warning(
|
||||
"IrHttp: could not sanitize company context in _dispatch: %s", e,
|
||||
)
|
||||
# Roll back the aborted transaction so subsequent DB queries in this
|
||||
# request can still execute. Without this PostgreSQL keeps the
|
||||
# connection in an InFailedSqlTransaction state and rejects every
|
||||
# further query in the same request.
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return super()._dispatch(endpoint)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user