You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spawning from reviewing #18066 by @blackmad which has the original investigation on this,
Normally, when usingEventBase, you would expect to be able to do naive comparisons like this isinstance(event.content.get("foo"), list) or isinstance(event.content.get("foo"), dict). But if event.freeze() was run beforehand, we actually need to take into account (list, tuple) and (dict, immutabledict).
What makes this even more subtle is that event.freeze() is only run when Synapse modules are configured.
It would be nice to for the type system, linting or anything to be able to catch this mistake. Or refactor things so that event.freeze() doesn't have such big downstream effects (perhaps we just make a copy that the Synapse module can do whatever it wants with).
Here is a list of places in the codebase where this matters (compiled from searching isinstance\(.+list and isinstance\(.+dict and manually inspecting if they're interacting with EventBase):
Places we already take this into account ✅
It looks like we already take this into account in a few places:
I've just had a thought on how we could solve all of the cases in #18117 pretty elegantly without having to muck about in the downstream code,
Instead of calling unfreeze at the spot we're trying to use it here, we could unfreeze after we're done with the frozen event in the third party module callbacks (where we called freeze in the first place).
Spawning from reviewing #18066 by @blackmad which has the original investigation on this,
Normally, when using
EventBase
, you would expect to be able to do naive comparisons like thisisinstance(event.content.get("foo"), list)
orisinstance(event.content.get("foo"), dict)
. But ifevent.freeze()
was run beforehand, we actually need to take into account(list, tuple)
and(dict, immutabledict)
.What makes this even more subtle is that
event.freeze()
is only run when Synapse modules are configured.It would be nice to for the type system, linting or anything to be able to catch this mistake. Or refactor things so that
event.freeze()
doesn't have such big downstream effects (perhaps we just make a copy that the Synapse module can do whatever it wants with).Related issues:
Here is a list of places in the codebase where this matters (compiled from searching
isinstance\(.+list
andisinstance\(.+dict
and manually inspecting if they're interacting withEventBase
):Places we already take this into account ✅
It looks like we already take this into account in a few places:
isinstance\(.+list
:synapse/synapse/events/auto_accept_invites.py
Line 160 in 95a85b1
synapse/synapse/handlers/message.py
Line 1780 in 95a85b1
synapse/synapse/handlers/message.py
Line 1789 in 95a85b1
synapse/synapse/push/bulk_push_rule_evaluator.py
Line 555 in 95a85b1
synapse/synapse/storage/controllers/state.py
Line 939 in 95a85b1
synapse/synapse/storage/controllers/state.py
Line 947 in 95a85b1
isinstance\(.+dict
):Places we still need to update ❌
But there are also other spots we also need to update:
isinstance\(.+list
:synapse/synapse/handlers/event_auth.py
Line 329 in 95a85b1
synapse/synapse/handlers/room_summary.py
Line 958 in 95a85b1
synapse/synapse/handlers/sliding_sync/__init__.py
Line 821 in 95a85b1
synapse/synapse/handlers/sliding_sync/__init__.py
Line 827 in 95a85b1
synapse/synapse/handlers/sliding_sync/room_lists.py
Line 1440 in 95a85b1
synapse/synapse/push/bulk_push_rule_evaluator.py
Line 571 in 95a85b1
synapse/synapse/push/push_tools.py
Line 78 in 95a85b1
synapse/synapse/push/push_tools.py
Line 82 in 95a85b1
synapse/synapse/storage/databases/main/events.py
Line 2067 in 95a85b1
isinstance\(.+dict
:synapse/synapse/handlers/event_auth.py
Line 335 in 95a85b1
synapse/synapse/events/utils.py
Line 864 in 95a85b1
synapse/synapse/events/utils.py
Line 874 in 95a85b1
synapse/synapse/handlers/event_auth.py
Line 335 in 95a85b1
synapse/synapse/handlers/room.py
Line 557 in 95a85b1
synapse/synapse/handlers/room.py
Line 576 in 95a85b1
synapse/synapse/push/bulk_push_rule_evaluator.py
Line 574 in 95a85b1
The text was updated successfully, but these errors were encountered: