diff --git a/CHANGES.md b/CHANGES.md
index c625e4d561..347aae8f67 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,7 +1,7 @@
-Synapse 1.59.0rc1 (2022-05-10)
+Synapse 1.59.0rc2 (2022-05-16)
==============================
-This release makes several changes that server administrators should be aware of:
+Synapse 1.59 makes several changes that server administrators should be aware of:
- Device name lookup over federation is now disabled by default. ([\#12616](https://github.com/matrix-org/synapse/issues/12616))
- The `synapse.app.appservice` and `synapse.app.user_dir` worker application types are now deprecated. ([\#12452](https://github.com/matrix-org/synapse/issues/12452), [\#12654](https://github.com/matrix-org/synapse/issues/12654))
@@ -10,6 +10,15 @@ See [the upgrade notes](https://github.com/matrix-org/synapse/blob/develop/docs/
Additionally, this release removes the non-standard `m.login.jwt` login type from Synapse. It can be replaced with `org.matrix.login.jwt` for identical behaviour. This is only used if `jwt_config.enabled` is set to `true` in the configuration. ([\#12597](https://github.com/matrix-org/synapse/issues/12597))
+Bugfixes
+--------
+
+- Fix a bug introduced in Synapse 1.58.0 where `/sync` would fail if the most recent event in a room was rejected. ([\#12729](https://github.com/matrix-org/synapse/issues/12729))
+
+
+Synapse 1.59.0rc1 (2022-05-10)
+==============================
+
Features
--------
diff --git a/debian/changelog b/debian/changelog
index fabc690bae..7f9bedd7ac 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+matrix-synapse-py3 (1.59.0~rc2) stable; urgency=medium
+
+ * New Synapse release 1.59.0rc2.
+
+ -- Synapse Packaging team <packages@matrix.org> Mon, 16 May 2022 12:52:15 +0100
+
matrix-synapse-py3 (1.59.0~rc1) stable; urgency=medium
* Adjust how the `exported-requirements.txt` file is generated as part of
diff --git a/pyproject.toml b/pyproject.toml
index e3d81ae5f1..1a2ddddb10 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -54,7 +54,7 @@ skip_gitignore = true
[tool.poetry]
name = "matrix-synapse"
-version = "1.59.0rc1"
+version = "1.59.0rc2"
description = "Homeserver for the Matrix decentralised comms protocol"
authors = ["Matrix.org Team and Contributors <packages@matrix.org>"]
license = "Apache-2.0"
diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py
index 59bbca2e32..944e2a5b0b 100644
--- a/synapse/storage/databases/main/stream.py
+++ b/synapse/storage/databases/main/stream.py
@@ -743,14 +743,17 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
"""
def _f(txn: LoggingTransaction) -> Optional[Tuple[int, int, str]]:
- sql = (
- "SELECT stream_ordering, topological_ordering, event_id"
- " FROM events"
- " WHERE room_id = ? AND stream_ordering <= ?"
- " AND NOT outlier"
- " ORDER BY stream_ordering DESC"
- " LIMIT 1"
- )
+ sql = """
+ SELECT stream_ordering, topological_ordering, event_id
+ FROM events
+ LEFT JOIN rejections USING (event_id)
+ WHERE room_id = ?
+ AND stream_ordering <= ?
+ AND NOT outlier
+ AND rejections.reason IS NULL
+ ORDER BY stream_ordering DESC
+ LIMIT 1
+ """
txn.execute(sql, (room_id, stream_ordering))
return cast(Optional[Tuple[int, int, str]], txn.fetchone())
|