typed_endpoint: Handle "dataclass_type" pydantic errors.

This commit adds error message for handling "dataclass_type"
pydantic errors. An example when this occurs is when group
setting value passed to update the setting is invalid like group
ID is passed directly and not in an object with "new" field and
other invalid values as well.
This commit is contained in:
Sahil Batra
2025-07-07 09:26:03 +05:30
committed by Tim Abbott
parent 2b52306c28
commit de1e08b9bf
2 changed files with 6 additions and 0 deletions

View File

@@ -316,6 +316,7 @@ def parse_view_func_signature(
ERROR_TEMPLATES = {
"bool_parsing": _("{var_name} is not a boolean"),
"bool_type": _("{var_name} is not a boolean"),
"dataclass_type": _("{var_name} does not have the expected format"),
"datetime_parsing": _("{var_name} is not a date"),
"datetime_type": _("{var_name} is not a date"),
"dict_type": _("{var_name} is not a dict"),

View File

@@ -1319,6 +1319,11 @@ class UserGroupAPITestCase(UserGroupTestCase):
leadership_group.deactivated = False
leadership_group.save()
# Test updating with value not in the form of GroupSettingChangeRequest
params[setting_name] = orjson.dumps(support_group.id).decode()
result = self.client_patch(f"/json/user_groups/{leadership_group.id}", info=params)
self.assert_json_error(result, f"{setting_name} does not have the expected format")
def test_update_user_group_permission_settings(self) -> None:
hamlet = self.example_user("hamlet")
check_add_user_group(hamlet.realm, "support", [hamlet], acting_user=hamlet)