-
Notifications
You must be signed in to change notification settings - Fork 421
Set type of user_id on is_server_admin to str
#18786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Confirmed that this fixes #18783. |
| ) | ||
|
|
||
| @cached(max_entries=100000) | ||
| async def is_server_admin(self, user: UserID) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why didn't our custom mypy plugin catch this?
synapse/scripts-dev/mypy_synapse_plugin.py
Lines 215 to 230 in 6514381
| def get_method_signature_hook( | |
| self, fullname: str | |
| ) -> Optional[Callable[[MethodSigContext], CallableType]]: | |
| if fullname.startswith( | |
| ( | |
| "synapse.util.caches.descriptors.CachedFunction.__call__", | |
| "synapse.util.caches.descriptors._LruCachedFunction.__call__", | |
| ) | |
| ): | |
| return cached_function_method_signature | |
| if fullname in ( | |
| "synapse.util.caches.descriptors._CachedFunctionDescriptor.__call__", | |
| "synapse.util.caches.descriptors._CachedListFunctionDescriptor.__call__", | |
| ): | |
| return check_is_cacheable_wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe our plugin currently allows proper type-checking of callers of cached functions, but it doesn't help with _invalidate_cache_and_stream. The arguments in that case are completely different. _invalidate_cache_and_stream takes in the function name and a list of parameters (which are typed as Any). The cached decorated takes the parameters directly.
I think what we actually want to do here is to make use of ParamSpec to "forward" the types from an inner to an outer function. Then mypy could warn that we were using str instead of UserID.
But we'd ideally go one step further and specify that _invalidate_cache_and_stream can only take in primitive types (because they are dropped into the DB, and then pulled out again without deserialisation). Either that, or store the types in the DB as well/pickle them so we can store things like UserID in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, so UserID is actually is_cacheable. And the only problem was mis-aligning str and UserID in the lookup to invalidate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and we can tell the cache is working by seeing #18783 😁
This allows the cache of this function to be invalidated. As we were calling `_invalidate_cache_and_stream` with a `str` instead of a `UserID` as this function expected, the cache was not actually being invalidated.
2b73bb0 to
477bb83
Compare
|
Base changed to |
(There was no 1.135.1.)
pkgsrc:
- Drop room creator power level patch, overtaken by upstream changes
in this release.
# Synapse 1.135.2 (2025-08-11)
This is the Synapse portion of the
[Matrix coordinated security release](https://matrix.org/blog/2025/07/security-predisclosure/).
This release includes support for
[room version](https://spec.matrix.org/v1.15/rooms/)
12 which fixes a number of security vulnerabilities, including
[CVE-2025-49090](https://www.cve.org/CVERecord?id=CVE-2025-49090).
The default room version is not changed. Not all clients will support
room version 12 immediately, and not all users will be using the
latest version of their clients. Large, public rooms are advised to
wait a few weeks before upgrading to room version 12 to allow users
throughout the Matrix ecosystem to update their clients.
### Bugfixes
- Fix invalidation of storage cache that was broken in 1.135.0.
([\#18786](element-hq/synapse#18786))
### Internal Changes
- Add a parameter to `upgrade_rooms(..)` to allow auto join local users.
([\#82](element-hq/synapse#82))
- Speed up upgrading a room with large numbers of banned users.
([\#18574](element-hq/synapse#18574))
And updates the few calling sites.
This allows the cache of this function to be invalidated. As we were calling
_invalidate_cache_and_streamwith astrinstead of aUserIDas this function expected, the cache was not actually being invalidated.We can't just pass
UserIDto_invalidate_cache_and_stream, as that function puts the args in a DB column and does not deserialise types when pulling them out.Once again fixes #18738. Broke in #18747.
Fix #18738
Fix #18783
Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.