mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
models: Improve conversion of CustomProfileField values.
These values are currently either a string already or a List[int]. We should do the conversion in do_update_user_custom_profile_data_if_changed properly: if the value is already a string, it can be used directly - if it's not, orjson.dumps is a more future-proof way of converting than str(). Using orjson.dumps here also allows us to change the converter of the USER type CustomProfileField to orjson.loads, which is nicer to have than ast.literal_eval. While orjson.dumps() and str() give the same output when given the special case of List[int], ast.literal_eval was previously used due to orjson.loads not being a good inverse function to str in general. That gets straightened out now.
This commit is contained in:
committed by
Tim Abbott
parent
cacff28578
commit
491f763f4e
@@ -1,4 +1,3 @@
|
||||
import ast
|
||||
import datetime
|
||||
import re
|
||||
import secrets
|
||||
@@ -20,6 +19,7 @@ from typing import (
|
||||
)
|
||||
|
||||
import django.contrib.auth
|
||||
import orjson
|
||||
from bitfield import BitField
|
||||
from bitfield.types import BitHandler
|
||||
from 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] = {
|
||||
|
||||
Reference in New Issue
Block a user