alert_words: Update remove_alert_word codepath to send event on commit.

Earlier, we were immediately enqueueing event in
'do_remove_alert_words' which can lead to a situation, if any
db operation is added after enqueueing event in future, where the
action function fails at a later stage.

Events should not be sent until we know we're not rolling back.

Fixes part of #30489.
This commit is contained in:
Prakhar Pratyush 2024-07-30 18:20:14 +05:30 committed by Tim Abbott
parent ba80266b7e
commit dc27711399
2 changed files with 2 additions and 1 deletions

View File

@ -18,6 +18,7 @@ def do_add_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) ->
notify_alert_words(user_profile, words)
@transaction.atomic(savepoint=False)
def do_remove_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) -> None:
words = remove_user_alert_words(user_profile, alert_words)
notify_alert_words(user_profile, words)

View File

@ -72,7 +72,7 @@ def add_user_alert_words(user_profile: UserProfile, new_words: Iterable[str]) ->
return user_alert_words(user_profile)
@transaction.atomic
@transaction.atomic(savepoint=False)
def remove_user_alert_words(user_profile: UserProfile, delete_words: Iterable[str]) -> list[str]:
# TODO: Ideally, this would be a bulk query, but Django doesn't have a `__iexact`.
# We can clean this up if/when PostgreSQL has more native support for case-insensitive fields.