Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

custom_profile_fields: Update transaction to be durable.

Prakhar Pratyush8b3d5a945594
diff --git a/zerver/actions/custom_profile_fields.py b/zerver/actions/custom_profile_fields.py
index e7b6e085062..ddd38ca1d59 100644
--- a/zerver/actions/custom_profile_fields.py
+++ b/zerver/actions/custom_profile_fields.py
@@ -162,47 +162,45 @@ def notify_user_update_custom_profile_data(
send_event_on_commit(user_profile.realm, event, get_user_ids_who_can_access_user(user_profile))
[email protected](durable=True)
def do_update_user_custom_profile_data_if_changed(
user_profile: UserProfile,
data: list[ProfileDataElementUpdateDict],
) -> None:
- with transaction.atomic():
- for custom_profile_field in data:
- field_value, created = CustomProfileFieldValue.objects.get_or_create(
- user_profile=user_profile, field_id=custom_profile_field["id"]
- )
+ for custom_profile_field in data:
+ field_value, created = CustomProfileFieldValue.objects.get_or_create(
+ user_profile=user_profile, field_id=custom_profile_field["id"]
+ )
- # field_value.value is a TextField() so we need to have field["value"]
- # in string form to correctly make comparisons and assignments.
- if isinstance(custom_profile_field["value"], str):
- custom_profile_field_value_string = custom_profile_field["value"]
- else:
- custom_profile_field_value_string = orjson.dumps(
- custom_profile_field["value"]
- ).decode()
-
- if not created and field_value.value == custom_profile_field_value_string:
- # If the field value isn't actually being changed to a different one,
- # we have nothing to do here for this field.
- continue
-
- field_value.value = custom_profile_field_value_string
- if field_value.field.is_renderable():
- field_value.rendered_value = render_stream_description(
- custom_profile_field_value_string, user_profile.realm
- )
- field_value.save(update_fields=["value", "rendered_value"])
- else:
- field_value.save(update_fields=["value"])
- notify_user_update_custom_profile_data(
- user_profile,
- {
- "id": field_value.field_id,
- "value": field_value.value,
- "rendered_value": field_value.rendered_value,
- "type": field_value.field.field_type,
- },
+ # field_value.value is a TextField() so we need to have field["value"]
+ # in string form to correctly make comparisons and assignments.
+ if isinstance(custom_profile_field["value"], str):
+ custom_profile_field_value_string = custom_profile_field["value"]
+ else:
+ custom_profile_field_value_string = orjson.dumps(custom_profile_field["value"]).decode()
+
+ if not created and field_value.value == custom_profile_field_value_string:
+ # If the field value isn't actually being changed to a different one,
+ # we have nothing to do here for this field.
+ continue
+
+ field_value.value = custom_profile_field_value_string
+ if field_value.field.is_renderable():
+ field_value.rendered_value = render_stream_description(
+ custom_profile_field_value_string, user_profile.realm
)
+ field_value.save(update_fields=["value", "rendered_value"])
+ else:
+ field_value.save(update_fields=["value"])
+ notify_user_update_custom_profile_data(
+ user_profile,
+ {
+ "id": field_value.field_id,
+ "value": field_value.value,
+ "rendered_value": field_value.rendered_value,
+ "type": field_value.field.field_type,
+ },
+ )
@transaction.atomic(durable=True)