Skip to content

Commit

Permalink
fix(migrate): raise exception even if db is not available (#22922) (#…
Browse files Browse the repository at this point in the history
…22999)

* fix(migrate): raise exception even if db is not available

* fix: wrap correctly

(cherry picked from commit c354b31)

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Oct 30, 2023
1 parent 62841eb commit 0f03ddd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions frappe/migrate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE

import contextlib
import functools
import json
import os
from textwrap import dedent
Expand Down Expand Up @@ -36,14 +38,18 @@


def atomic(method):
@functools.wraps(method)
def wrapper(*args, **kwargs):
try:
ret = method(*args, **kwargs)
frappe.db.commit()
return ret
except Exception:
frappe.db.rollback()
raise
except Exception as e:
# database itself can be gone while attempting rollback.
# We should preserve original exception in this case.
with contextlib.suppress(Exception):
frappe.db.rollback()
raise e

return wrapper

Expand Down

0 comments on commit 0f03ddd

Please sign in to comment.