From b8a333004a9d7591ecf2c477c50e06f122f40565 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 5 Feb 2025 13:07:49 +0100 Subject: [PATCH] Fix legacy modules `check_username_for_spam` (#18135) Broke in #17916, as the signature inspection incorrectly looks at the wrapper function. We fix this by setting the signature on the wrapper function to that of the wrapped function via `@functools.wraps`. --- changelog.d/18135.bugfix | 1 + synapse/module_api/callbacks/spamchecker_callbacks.py | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 changelog.d/18135.bugfix diff --git a/changelog.d/18135.bugfix b/changelog.d/18135.bugfix new file mode 100644 index 000000000..998914a81 --- /dev/null +++ b/changelog.d/18135.bugfix @@ -0,0 +1 @@ +Fix user directory search when using a legacy module with a `check_username_for_spam` callback. Broke in v1.122.0. diff --git a/synapse/module_api/callbacks/spamchecker_callbacks.py b/synapse/module_api/callbacks/spamchecker_callbacks.py index a2f328caf..9bc572422 100644 --- a/synapse/module_api/callbacks/spamchecker_callbacks.py +++ b/synapse/module_api/callbacks/spamchecker_callbacks.py @@ -19,6 +19,7 @@ # # +import functools import inspect import logging from typing import ( @@ -297,6 +298,7 @@ def load_legacy_spam_checkers(hs: "synapse.server.HomeServer") -> None: "Bad signature for callback check_registration_for_spam", ) + @functools.wraps(wrapped_func) def run(*args: Any, **kwargs: Any) -> Awaitable: # Assertion required because mypy can't prove we won't change `f` # back to `None`. See