realm_settings: Send event on commit in do_set...authentication_methods.

Earlier, we were using 'send_event' in
'do_set_realm_authentication_methods' which can lead to a situation
where we enqueue events but there's an error at a later stage in
the codepath using this function.

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-08-22 14:39:18 +05:30 committed by Tim Abbott
parent 63064e926b
commit c0dc005d05
1 changed files with 21 additions and 21 deletions

View File

@ -334,11 +334,11 @@ def validate_plan_for_authentication_methods(
)
@transaction.atomic(savepoint=False)
def do_set_realm_authentication_methods(
realm: Realm, authentication_methods: dict[str, bool], *, acting_user: UserProfile | None
) -> None:
old_value = realm.authentication_methods_dict()
with transaction.atomic():
for key, value in authentication_methods.items():
# This does queries in a loop, but this isn't a performance sensitive
# path and is only run rarely.
@ -371,7 +371,7 @@ def do_set_realm_authentication_methods(
property="default",
data=event_data,
)
send_event(realm, event, active_user_ids(realm.id))
send_event_on_commit(realm, event, active_user_ids(realm.id))
def do_set_realm_stream(