zulip/zerver/tornado
Udit107710 ef741bf317 messages: Return shallow copy of message object.
When more than one outgoing webhook is configured,
the message which is send to the webhook bot passes
through finalize_payload function multiple times,
which mutated the message dict in a way that many keys
were lost from the dict obj.

This commit fixes that problem by having
`finalize_payload` return a shallow copy of the
incoming dict, instead of mutating it.  We still
mutate dicts inside of `post_process_dicts`, though,
for performance reasons.

This was slightly modified by @showell to fix the
`test_both_codepaths` test that was added concurrently
to this work.  (I used a slightly verbose style in the
tests to emphasize the transformation from `wide_dict`
to `narrow_dict`.)

I also removed a deepcopy call inside
`get_client_payload`, since we now no longer mutate
in `finalize_payload`.

Finally, I added some comments here and there.

For testing, I mostly protect against the root
cause of the bug happening again, by adding a line
to make sure that `sender_realm_id` does not get
wiped out from the "wide" dictionary.

A better test would exercise the actual code that
exposed the bug here by sending a message to a bot
with two or more services attached to it.  I will
do that in a future commit.

Fixes #14384
2020-03-29 15:12:27 -07:00
..
__init__.py
application.py dependencies: Remove WebSockets system for sending messages. 2020-01-14 22:34:00 -08:00
autoreload.py tornado: Fix bugs in Tornado autoreload library. 2019-08-02 12:47:49 -07:00
descriptors.py typing: Use TYPE_CHECKING when dealing with cyclic dependencies. 2019-07-31 12:19:39 -07:00
event_queue.py messages: Return shallow copy of message object. 2020-03-29 15:12:27 -07:00
exceptions.py cleanup: Delete leading newlines. 2019-08-06 23:29:11 -07:00
handlers.py middleware: Use request.user for logging when possible. 2020-03-09 13:54:58 -07:00
ioloop_logging.py mypy: Fix missing type annotation in tornado code. 2018-11-20 19:08:14 -08:00
sharding.py dependencies: Remove WebSockets system for sending messages. 2020-01-14 22:34:00 -08:00
views.py middleware: Log user.id/realm.string_id instead of _email. 2020-03-09 13:54:58 -07:00