summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Eastwood <eric.eastwood@beta.gouv.fr>2024-06-10 09:48:38 -0500
committerGitHub <noreply@github.com>2024-06-10 09:48:38 -0500
commit265ee88f34e8aec4c242af5b6c428bd1331fa354 (patch)
treedab3d4217a3680e8cacb006e44f058603b65cc7a
parentSupport MSC3916 by adding a federation `/download` endpoint (#17172) (diff)
downloadsynapse-265ee88f34e8aec4c242af5b6c428bd1331fa354.tar.xz
Wrong retention policy being used when filtering events (lint `ControlVarUsedAfterBlockViolation` `WPS441`) (#17272)
Fix loop var being used outside block.

Before this change, we were always using the last room_id's retention policy for all events being filtered.

I found this bug with the [new lint rule, `ControlVarUsedAfterBlockViolation` `WPS441`](https://github.com/astral-sh/ruff/pull/11769), that I re-implemented in `ruff`. Shout-out to @reivilibre for all the help in the beginning! 

### Pull Request Checklist

<!-- Please read
https://element-hq.github.io/synapse/latest/development/contributing_guide.html
before submitting your pull request -->

* [x] Pull request is based on the develop branch
* [x] Pull request includes a [changelog
file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog).
The entry should:
- Be a short description of your change which makes sense to users.
"Fixed a bug that prevented receiving messages from other servers."
instead of "Moved X method from `EventStore` to `EventWorkerStore`.".
  - Use markdown where necessary, mostly for `code blocks`.
  - End with either a period (.) or an exclamation mark (!).
  - Start with a capital letter.
- Feel free to credit yourself, by adding a sentence "Contributed by
@github_username." or "Contributed by [Your Name]." to the end of the
entry.
* [x] [Code
style](https://element-hq.github.io/synapse/latest/code_style.html) is
correct
(run the
[linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))
-rw-r--r--changelog.d/17272.bugfix1
-rw-r--r--synapse/visibility.py2
2 files changed, 2 insertions, 1 deletions
diff --git a/changelog.d/17272.bugfix b/changelog.d/17272.bugfix
new file mode 100644
index 0000000000..83e7ca426a
--- /dev/null
+++ b/changelog.d/17272.bugfix
@@ -0,0 +1 @@
+Fix wrong retention policy being used when filtering events.
diff --git a/synapse/visibility.py b/synapse/visibility.py
index 09a947ef15..c891bd845b 100644
--- a/synapse/visibility.py
+++ b/synapse/visibility.py
@@ -151,7 +151,7 @@ async def filter_events_for_client(
             filter_send_to_client=filter_send_to_client,
             sender_ignored=event.sender in ignore_list,
             always_include_ids=always_include_ids,
-            retention_policy=retention_policies[room_id],
+            retention_policy=retention_policies[event.room_id],
             state=state_after_event,
             is_peeking=is_peeking,
             sender_erased=erased_senders.get(event.sender, False),