Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Infrastructure / Support

Bugfixes
-----------
* Fix error page rendering when a database error leaves the transaction in a failed state (e.g. when a missing migration such as the one adding ``account.attributes`` causes an ``InFailedSqlTransaction`` error) [see `PR #2100 <https://www.github.com/FlexMeasures/flexmeasures/pull/2100>`_]


v0.31.3 | April 11, 2026
Expand Down
16 changes: 16 additions & 0 deletions flexmeasures/utils/error_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ def error_handling_router(error: HTTPException):
else:
log_error(error, getattr(error, "description", str(error)))

# Roll back any failed DB transaction so subsequent queries (e.g. in
# the error-page template) can run in a clean state. This is needed
# when a database error (e.g. UndefinedColumn due to a missing
# migration) leaves the PostgreSQL transaction in an aborted state;
# without the rollback every following query in the same request would
# fail with "InFailedSqlTransaction" and the error page itself could
# not be rendered properly.
try:
from flexmeasures.data import db

db.session.rollback()
except Exception as rollback_exc:
current_app.logger.warning(
"Could not roll back DB session in error handler: %s", rollback_exc
)

error_text = getattr(
error, "description", f"Something went wrong: {error.__class__.__name__}"
)
Expand Down