fix(mcp): prevent PendingRollbackError from poisoned sessions after SSL drops (#38934)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit d331a043a3)
This commit is contained in:
Amin Ghadersohi
2026-03-30 16:30:15 +02:00
committed by Michael S. Molina
parent f1f757b5c5
commit bda02a3fdc
5 changed files with 199 additions and 56 deletions

View File

@@ -742,7 +742,13 @@ async def generate_chart( # noqa: C901
chart.id,
exc_info=True,
)
db.session.rollback()
try:
db.session.rollback() # pylint: disable=consider-using-transaction
except SQLAlchemyError:
logger.warning(
"Database rollback failed during chart re-fetch error handling",
exc_info=True,
)
chart_data = {
"id": chart.id,
"slice_name": chart.slice_name,
@@ -805,6 +811,14 @@ async def generate_chart( # noqa: C901
return GenerateChartResponse.model_validate(result)
except (CommandException, SQLAlchemyError, KeyError, ValueError) as e:
from superset import db
try:
db.session.rollback() # pylint: disable=consider-using-transaction
except SQLAlchemyError:
logger.warning(
"Database rollback failed during error handling", exc_info=True
)
await ctx.error(
"Chart generation failed: error=%s, execution_time_ms=%s"
% (