Skip to content

Commit 9d81bb7

Browse files
authored
Always treat RETURNING as supported by SQL engines (#19047)
Can do this now that SQLite 3.35.0 added support for `RETURNING`. > The RETURNING syntax has been supported by SQLite since version 3.35.0 (2021-03-12). > > *-- https://sqlite.org/lang_returning.html* This also bumps the minimum supported SQLite version according to Synapse's [deprecation policy](https://element-hq.github.io/synapse/latest/deprecation_policy.html#platform-dependencies). Fix #17577
1 parent 40893be commit 9d81bb7

File tree

16 files changed

+80
-186
lines changed

16 files changed

+80
-186
lines changed

.ci/scripts/calculate_jobs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,24 @@ def set_output(key: str, value: str):
9999

100100
# First calculate the various sytest jobs.
101101
#
102-
# For each type of test we only run on bullseye on PRs
102+
# For each type of test we only run on bookworm on PRs
103103

104104

105105
sytest_tests = [
106106
{
107-
"sytest-tag": "bullseye",
107+
"sytest-tag": "bookworm",
108108
},
109109
{
110-
"sytest-tag": "bullseye",
110+
"sytest-tag": "bookworm",
111111
"postgres": "postgres",
112112
},
113113
{
114-
"sytest-tag": "bullseye",
114+
"sytest-tag": "bookworm",
115115
"postgres": "multi-postgres",
116116
"workers": "workers",
117117
},
118118
{
119-
"sytest-tag": "bullseye",
119+
"sytest-tag": "bookworm",
120120
"postgres": "multi-postgres",
121121
"workers": "workers",
122122
"reactor": "asyncio",
@@ -127,11 +127,11 @@ def set_output(key: str, value: str):
127127
sytest_tests.extend(
128128
[
129129
{
130-
"sytest-tag": "bullseye",
130+
"sytest-tag": "bookworm",
131131
"reactor": "asyncio",
132132
},
133133
{
134-
"sytest-tag": "bullseye",
134+
"sytest-tag": "bookworm",
135135
"postgres": "postgres",
136136
"reactor": "asyncio",
137137
},

.github/workflows/latest_deps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ jobs:
139139
fail-fast: false
140140
matrix:
141141
include:
142-
- sytest-tag: bullseye
142+
- sytest-tag: bookworm
143143

144-
- sytest-tag: bullseye
144+
- sytest-tag: bookworm
145145
postgres: postgres
146146
workers: workers
147147
redis: redis

.github/workflows/twisted_trunk.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ jobs:
108108
if: needs.check_repo.outputs.should_run_workflow == 'true'
109109
runs-on: ubuntu-latest
110110
container:
111-
# We're using debian:bullseye because it uses Python 3.9 which is our minimum supported Python version.
111+
# We're using bookworm because that's what Debian oldstable is at the time of writing.
112112
# This job is a canary to warn us about unreleased twisted changes that would cause problems for us if
113113
# they were to be released immediately. For simplicity's sake (and to save CI runners) we use the oldest
114114
# version, assuming that any incompatibilities on newer versions would also be present on the oldest.
115-
image: matrixdotorg/sytest-synapse:bullseye
115+
image: matrixdotorg/sytest-synapse:bookworm
116116
volumes:
117117
- ${{ github.workspace }}:/src
118118

changelog.d/19047.doc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update the link to the Debian oldstable package for SQLite.

changelog.d/19047.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Always treat `RETURNING` as supported by SQL engines, now that the minimum-supported versions of both SQLite and PostgreSQL support it.

changelog.d/19047.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove support for SQLite < 3.37.2.

docs/deprecation_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ people building from source should ensure they can fetch recent versions of Rust
2121
(e.g. by using [rustup](https://rustup.rs/)).
2222

2323
The oldest supported version of SQLite is the version
24-
[provided](https://packages.debian.org/bullseye/libsqlite3-0) by
24+
[provided](https://packages.debian.org/oldstable/libsqlite3-0) by
2525
[Debian oldstable](https://wiki.debian.org/DebianOldStable).
2626

2727

docs/development/contributing_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ The following command will let you run the integration test with the most common
320320
configuration:
321321
322322
```sh
323-
$ docker run --rm -it -v /path/where/you/have/cloned/the/repository\:/src:ro -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapse:bullseye
323+
$ docker run --rm -it -v /path/where/you/have/cloned/the/repository\:/src:ro -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapse:bookworm
324324
```
325325
(Note that the paths must be full paths! You could also write `$(realpath relative/path)` if needed.)
326326

synapse/storage/database.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,36 +1161,17 @@ def simple_insert_returning_txn(
11611161
SQLite versions that don't support it).
11621162
"""
11631163

1164-
if txn.database_engine.supports_returning:
1165-
sql = "INSERT INTO %s (%s) VALUES(%s) RETURNING %s" % (
1166-
table,
1167-
", ".join(k for k in values.keys()),
1168-
", ".join("?" for _ in values.keys()),
1169-
", ".join(k for k in returning),
1170-
)
1171-
1172-
txn.execute(sql, list(values.values()))
1173-
row = txn.fetchone()
1174-
assert row is not None
1175-
return row
1176-
else:
1177-
# For old versions of SQLite we do a standard insert and then can
1178-
# use `last_insert_rowid` to get at the row we just inserted
1179-
DatabasePool.simple_insert_txn(
1180-
txn,
1181-
table=table,
1182-
values=values,
1183-
)
1184-
txn.execute("SELECT last_insert_rowid()")
1185-
row = txn.fetchone()
1186-
assert row is not None
1187-
(rowid,) = row
1164+
sql = "INSERT INTO %s (%s) VALUES(%s) RETURNING %s" % (
1165+
table,
1166+
", ".join(k for k in values.keys()),
1167+
", ".join("?" for _ in values.keys()),
1168+
", ".join(k for k in returning),
1169+
)
11881170

1189-
row = DatabasePool.simple_select_one_txn(
1190-
txn, table=table, keyvalues={"rowid": rowid}, retcols=returning
1191-
)
1192-
assert row is not None
1193-
return row
1171+
txn.execute(sql, list(values.values()))
1172+
row = txn.fetchone()
1173+
assert row is not None
1174+
return row
11941175

11951176
async def simple_insert_many(
11961177
self,

synapse/storage/databases/main/delayed_events.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -347,33 +347,28 @@ def process_target_delayed_event_txn(
347347
EventDetails,
348348
Optional[Timestamp],
349349
]:
350-
sql_cols = ", ".join(
351-
(
352-
"room_id",
353-
"event_type",
354-
"state_key",
355-
"origin_server_ts",
356-
"content",
357-
"device_id",
358-
)
359-
)
360-
sql_update = "UPDATE delayed_events SET is_processed = TRUE"
361-
sql_where = "WHERE delay_id = ? AND user_localpart = ? AND NOT is_processed"
362-
sql_args = (delay_id, user_localpart)
363350
txn.execute(
351+
"""
352+
UPDATE delayed_events
353+
SET is_processed = TRUE
354+
WHERE delay_id = ? AND user_localpart = ?
355+
AND NOT is_processed
356+
RETURNING
357+
room_id,
358+
event_type,
359+
state_key,
360+
origin_server_ts,
361+
content,
362+
device_id
363+
""",
364364
(
365-
f"{sql_update} {sql_where} RETURNING {sql_cols}"
366-
if self.database_engine.supports_returning
367-
else f"SELECT {sql_cols} FROM delayed_events {sql_where}"
365+
delay_id,
366+
user_localpart,
368367
),
369-
sql_args,
370368
)
371369
row = txn.fetchone()
372370
if row is None:
373371
raise NotFoundError("Delayed event not found")
374-
elif not self.database_engine.supports_returning:
375-
txn.execute(f"{sql_update} {sql_where}", sql_args)
376-
assert txn.rowcount == 1
377372

378373
event = EventDetails(
379374
RoomID.from_string(row[0]),

0 commit comments

Comments
 (0)