Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Improve conversion of CustomProfileField values.
Mateusz Mandera491f763f4e05
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex e57016c89aa..21a2e3dd700 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -7746,17 +7746,24 @@ def do_update_user_custom_profile_data_if_changed(user_profile=user_profile, field_id=custom_profile_field["id"])- if not created and field_value.value == str(custom_profile_field["value"]):+ # 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.- # Note: field_value.value is a TextField() so we need to cast field['value']- # to a string for the comparison in this if.continue- field_value.value = str(custom_profile_field["value"])+ field_value.value = custom_profile_field_value_stringif field_value.field.is_renderable():field_value.rendered_value = render_stream_description(- str(custom_profile_field["value"])+ custom_profile_field_value_string)field_value.save(update_fields=["value", "rendered_value"])else:diff --git a/zerver/models.py b/zerver/models.pyindex ebd2932fb16..8ba0f5154e6 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -1,4 +1,3 @@-import astimport datetimeimport reimport secrets@@ -20,6 +19,7 @@ from typing import ()import django.contrib.auth+import orjsonfrom bitfield import BitFieldfrom bitfield.types import BitHandlerfrom django.conf import settings@@ -3878,7 +3878,7 @@ class CustomProfileField(models.Model):(SELECT, gettext_lazy("List of options"), validate_select_field, str, "SELECT"),]USER_FIELD_TYPE_DATA: List[UserFieldElement] = [- (USER, gettext_lazy("Person picker"), check_valid_user_ids, ast.literal_eval, "USER"),+ (USER, gettext_lazy("Person picker"), check_valid_user_ids, orjson.loads, "USER"),]SELECT_FIELD_VALIDATORS: Dict[int, ExtendedValidator] = {