message send: Do not re-assign widget_content variable.

After re-assignment, mypy will still think the type of
`widget_content` to be `str`, not `Dict`. So we need to
create a new variable.
This is a prep change for stronger type checking in this
code.
This commit is contained in:
Abhijeet Prasad Bodas
2021-05-20 20:42:21 +05:30
committed by Tim Abbott
parent 334db60a07
commit d6871dbae5

View File

@@ -1813,7 +1813,7 @@ def build_message_send_dict(
service_bot_tuples=info["service_bot_tuples"], service_bot_tuples=info["service_bot_tuples"],
wildcard_mention_user_ids=wildcard_mention_user_ids, wildcard_mention_user_ids=wildcard_mention_user_ids,
links_for_embed=links_for_embed, links_for_embed=links_for_embed,
widget_content=message_dict.get("widget_content", None), widget_content=message_dict.get("widget_content_dict", None),
) )
return message_send_dict return message_send_dict
@@ -3116,14 +3116,15 @@ def check_message(
if id is not None: if id is not None:
raise ZephyrMessageAlreadySentException(id) raise ZephyrMessageAlreadySentException(id)
widget_content_dict = None
if widget_content is not None: if widget_content is not None:
try: try:
widget_content = orjson.loads(widget_content) widget_content_dict = orjson.loads(widget_content)
except orjson.JSONDecodeError: except orjson.JSONDecodeError:
raise JsonableError(_("Widgets: API programmer sent invalid JSON content")) raise JsonableError(_("Widgets: API programmer sent invalid JSON content"))
try: try:
check_widget_content(widget_content) check_widget_content(widget_content_dict)
except ValidationError as error: except ValidationError as error:
raise JsonableError( raise JsonableError(
_("Widgets: {error_msg}").format( _("Widgets: {error_msg}").format(
@@ -3137,7 +3138,7 @@ def check_message(
"local_id": local_id, "local_id": local_id,
"sender_queue_id": sender_queue_id, "sender_queue_id": sender_queue_id,
"realm": realm, "realm": realm,
"widget_content": widget_content, "widget_content_dict": widget_content_dict,
} }
message_send_dict = build_message_send_dict(message_dict, email_gateway) message_send_dict = build_message_send_dict(message_dict, email_gateway)