Fix overly restrictive typeguards in get_rooms_that_allow_join#18066
Open
blackmad wants to merge 6 commits intoelement-hq:developfrom
Open
Fix overly restrictive typeguards in get_rooms_that_allow_join#18066blackmad wants to merge 6 commits intoelement-hq:developfrom
blackmad wants to merge 6 commits intoelement-hq:developfrom
Conversation
This was causing a bug that was only occuring when the server had modules loaded and there were unjoined space-visible rooms in a hierarchy. This fix is a result of the following investigation: Symptom: new 'space-visible' rooms are not showing up in /hierarchy Reason: because get_rooms_that_allow_join is checking that the allow key is a list, and it's coming back as a tuple https://github.com/element-hq/synapse/blob/develop/synapse/handlers/event_auth.py#L329 -> Reason: when the room is created, the join_rules event calls check_event_allowed - https://github.com/element-hq/synapse/blob/develop/synapse/handlers/message.py#L1289 - which calls event.freeze() which seems to be changing lists to tuples - https://github.com/element-hq/synapse/blob/develop/synapse/module_api/callbacks/third_party_event_rules_callbacks.py#L294 --> so that when the event is being pulled from cache, the allow list is a tuple. But when I restart the server, it gets pulled from the DB and deserialized as a list.
|
|
f8d67fc to
c3e6500
Compare
MadLittleMods
approved these changes
Jan 30, 2025
| # If allowed is of the wrong form, then only allow invited users. | ||
| allow_list = join_rules_event.content.get("allow", []) | ||
| if not isinstance(allow_list, list): | ||
| if not isinstance(allow_list, (list, tuple)): |
Contributor
We're matching the `(list, tuple)` combo
MadLittleMods
requested changes
Jan 30, 2025
| # If allowed is of the wrong form, then only allow invited users. | ||
| allow_list = join_rules_event.content.get("allow", []) | ||
| if not isinstance(allow_list, list): | ||
| if not isinstance(allow_list, (list, tuple)): |
Contributor
There was a problem hiding this comment.
@blackmad I've just had a thought on how we can fix all of the cases mentioned in #18117 without having to modify any of the downstream code, see #18103 (comment)
Going to leave this PR until we figure out if that is a viable solution to all of this.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This was causing a bug that was only occuring when the server had modules loaded and there were unjoined space-visible rooms in a hierarchy.
This fix is a result of the following investigation:
Symptom: new 'space-visible' rooms are not showing up in
/hierarchyReason: becauseget_rooms_that_allow_joinis checking that the allow key is a list, and it's coming back as a tuplesynapse/handlers/event_auth.py#L329Reason: when the room is created, the join_rules event creation logic calls
check_event_allowed-synapse/handlers/message.py#L1289- which callsevent.freeze()(insynapse/module_api/callbacks/third_party_event_rules_callbacks.py#L294) which seems to be changing lists to tuples - so that when the event is being pulled from cache, the allow list is a tuple. But when I restart the server, it gets pulled from the DB and deserialized as a list.Part of #18117
Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.(run the linters)