Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix ModuleApi.looping_background_call for non-async functions #11524

Merged
merged 3 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11524.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a regression in Synapse 1.48.0 where the module API's `looping_background_call` method would spam errors to the logs when given a non-async function.
5 changes: 2 additions & 3 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
create_requester,
)
from synapse.util import Clock
from synapse.util.async_helpers import maybe_awaitable
from synapse.util.caches.descriptors import cached

if TYPE_CHECKING:
Expand Down Expand Up @@ -1014,9 +1015,7 @@ def looping_background_call(
run_as_background_process,
msec,
desc,
f,
*args,
**kwargs,
lambda: maybe_awaitable(f(*args, **kwargs)),
Comment on lines -1017 to +1018
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shame mypy couldn't have spotted this.

I wonder how feasible a mypy plugin would be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParamSpec would have caught this, if only mypy had support for it.
I'm not a big fan of plugins since they tie you to a specific type checker.

)
else:
logger.warning(
Expand Down