Skip to content

Commit

Permalink
chore: Move function out of receiver (#76273)
Browse files Browse the repository at this point in the history
Move stuff out of receivers second try after:
#76255
Just making it backwards compatible instead cuz requires didn't work

getsentry PR moving imports:
getsentry/getsentry#14925
  • Loading branch information
schew2381 committed Aug 15, 2024
1 parent b0c30d9 commit b25f2c8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/sentry/utils/db.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import logging
from collections.abc import Sequence
from contextlib import ExitStack
from functools import wraps

import sentry_sdk
from django.db import DEFAULT_DB_ALIAS, connections, transaction
from django.db import DEFAULT_DB_ALIAS, connections, router, transaction
from django.db.utils import OperationalError, ProgrammingError
from sentry_sdk.integrations import Integration


def handle_db_failure(func, model, wrap_in_transaction: bool = True):
@wraps(func)
def wrapped(*args, **kwargs):
try:
if wrap_in_transaction:
with transaction.atomic(router.db_for_write(model)):
return func(*args, **kwargs)
else:
return func(*args, **kwargs)
except (ProgrammingError, OperationalError):
logging.exception("Failed processing signal %s", func.__name__)
return

return wrapped


def atomic_transaction(
using: str | Sequence[str], savepoint: bool = True
) -> transaction.Atomic | ExitStack:
Expand Down

0 comments on commit b25f2c8

Please sign in to comment.