-
Notifications
You must be signed in to change notification settings - Fork 562
Concept: Rust database access via Python database connection pool (via runInteraction) (LLM splat v1)
#19846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MadLittleMods
wants to merge
58
commits into
develop
Choose a base branch
from
madlittlemods/rust-db-access-using-python-db-pool-run-interaction-llm1
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,728
−202
Draft
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
3696e7c
Splat based on #19824
MadLittleMods c63b40e
A little bit of iterating
MadLittleMods bb4c555
Adjust comment
MadLittleMods 8f0768d
LLM attempt 1
MadLittleMods d9a111b
LLM attempt at simplifying
MadLittleMods 6b5e9f2
Partial `Row`
MadLittleMods d3af0c4
LLM further `Row`
MadLittleMods 65ba851
Concrete `Row` type
MadLittleMods 0226a67
Add comments why row expectations
MadLittleMods 7bf4b6a
Non-working: Add `test_versions.py`
MadLittleMods 8270087
Fix test failing with `RuntimeError: Tokio runtime is not running`
MadLittleMods 0b6a973
Passing `tests_versions.py`: Wait real time for tokio thread pool to …
MadLittleMods 158b4a0
Revert "Passing `tests_versions.py`: Wait real time for tokio thread …
MadLittleMods e2ec3f1
`FakeChannel.await_rust_result`
MadLittleMods 1dcf17d
Rename: `await_rust_result` -> `await_result_with_rust`
MadLittleMods 357860c
Specify features to enable
MadLittleMods ca1371e
Refactor `deferred` and `tokio_runtime` to their own crates
MadLittleMods f76c8c1
Refactor to remove `SynapseConfig` from shared code
MadLittleMods 29e5830
Fix Rust warnings
MadLittleMods 5b1a1ae
WIP: `RoomCreationPreset`
MadLittleMods 9688d48
Fix `RoomCreationPreset`
MadLittleMods 941188c
Remove unused `msc4222`
MadLittleMods 7c2790a
Serde `UnstableFeatureMap`
MadLittleMods 7aec5a0
Stub remaining features
MadLittleMods d9a02d3
Merge branch 'develop' into madlittlemods/rust-db-access-using-python…
MadLittleMods 19c0777
Add changelog
MadLittleMods 5f23dc6
Fix lint
MadLittleMods 1d6eb1e
Remove `await_result_with_rust` in favor of updating `await_result` w…
MadLittleMods 4eec02c
Explain possible better future for async fn that need to be `Send`
MadLittleMods dc93a23
Fix grammar, add intended fix
MadLittleMods 874178a
`poll_once` instead of `futures::executor::block_on`
MadLittleMods 505b599
Panic for programming error
MadLittleMods d40adfa
Explain why `poll_once`
MadLittleMods 065c5cb
Non-working: Try to save/restore logcontext
MadLittleMods 441e580
Fix logcontext
MadLittleMods 7466574
Less wordy
MadLittleMods 37ff660
Align imports on `OnceCell` which has `get_or_try_init`
MadLittleMods f42ba67
Avoid circular import issues
MadLittleMods c21dbbd
Rename `Value` -> `DbValue`
MadLittleMods ce68c0f
Merge branch 'develop' into madlittlemods/rust-db-access-using-python…
MadLittleMods 2860e4e
LLM attempt at switching back to `Store` with `dyn DatabasePool`
MadLittleMods 683f264
LLM simplify `dyn DatabasePool`
MadLittleMods adeb039
Sync trait not needed on `run_interaction`
MadLittleMods a4e4af7
"Dyn-compatibility" is the new name for "object safety"
MadLittleMods 87ca67d
Update comments
MadLittleMods 590fd2b
Fill in the rest of `rust/src/handlers/versions.rs`
MadLittleMods 2a609a5
Fill in missing experimental config
MadLittleMods 59228e5
Fill in the rest of the config
MadLittleMods 55d89f9
Use `time.sleep(0)` to align with decision in #19871
MadLittleMods 7ed525d
Rename `SynapseConfig` -> `SynapseHomeServerConfig`
MadLittleMods 8ddab4f
Iterate on Database trait comments
MadLittleMods 79a8cc1
Rename `Row` -> `DbRow`
MadLittleMods a2e68ad
Explain more about `python_db_pool`
MadLittleMods 0090330
Iterate on `python_db_pool` comments
MadLittleMods 6195074
Only return runInteraction result if it succeeded
MadLittleMods b5ea2f7
Avoid `String` allocation
MadLittleMods 5ce6b8a
Better `failure_to_pyerr`
MadLittleMods 74ad3b2
Merge branch 'develop' into madlittlemods/rust-db-access-using-python…
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allow Rust code to have database access via Python database connection pool. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * This file is licensed under the Affero General Public License (AGPL) version 3. | ||
| * | ||
| * Copyright (C) 2026 Element Creations Ltd | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * See the GNU Affero General Public License for more details: | ||
| * <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
| * | ||
| */ | ||
|
|
||
| use std::collections::BTreeSet; | ||
| use std::str::FromStr; | ||
|
|
||
| use pyo3::{exceptions::PyRuntimeError, prelude::*}; | ||
|
|
||
| /// A Rust-side view of Synapse's Python `HomeServerConfig`. | ||
| /// | ||
| /// This only mirrors the subset of config that the Rust handlers need, rather | ||
| /// than the whole thing. Thanks to `#[derive(FromPyObject)]`, each field is | ||
| /// pulled directly off the corresponding attribute of the Python `config` | ||
| /// object, so you can populate it in one shot with | ||
| /// `homeserver.getattr("config")?.extract()?`. | ||
| #[derive(FromPyObject, Clone)] | ||
| pub struct SynapseHomeServerConfig { | ||
| pub room: RoomConfig, | ||
| pub auth: AuthConfig, | ||
| pub server: ServerConfig, | ||
| pub experimental: ExperimentalConfig, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub enum RoomCreationPreset { | ||
| PrivateChat, | ||
| PublicChat, | ||
| TrustedPrivateChat, | ||
| } | ||
|
|
||
| impl FromStr for RoomCreationPreset { | ||
| type Err = PyErr; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| Ok(match s { | ||
| "private_chat" => RoomCreationPreset::PrivateChat, | ||
| "public_chat" => RoomCreationPreset::PublicChat, | ||
| "trusted_private_chat" => RoomCreationPreset::TrustedPrivateChat, | ||
| other => { | ||
| return Err(PyRuntimeError::new_err(format!( | ||
| "Unknown variant {other:?} does not translate to `RoomCreationPreset`. \ | ||
| This is a Synapse programming error." | ||
| ))) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl<'a, 'py> FromPyObject<'a, 'py> for RoomCreationPreset { | ||
| type Error = PyErr; | ||
|
|
||
| fn extract(value: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> { | ||
| value.extract::<&str>()?.parse() | ||
| } | ||
| } | ||
|
|
||
| #[derive(FromPyObject, Clone)] | ||
| pub struct RoomConfig { | ||
| pub encryption_enabled_by_default_for_room_presets: BTreeSet<RoomCreationPreset>, | ||
| } | ||
|
|
||
| #[derive(FromPyObject, Clone)] | ||
| pub struct AuthConfig { | ||
| pub login_via_existing_enabled: bool, | ||
| } | ||
| #[derive(FromPyObject, Clone)] | ||
| pub struct ServerConfig { | ||
| pub max_event_delay_ms: Option<u64>, | ||
| } | ||
|
|
||
| #[derive(FromPyObject, Clone)] | ||
| pub struct ExperimentalConfig { | ||
| pub msc3026_enabled: bool, | ||
| pub msc3773_enabled: bool, | ||
| pub msc2815_enabled: bool, | ||
| pub msc3881_enabled: bool, | ||
| pub msc3874_enabled: bool, | ||
| pub msc3912_enabled: bool, | ||
| pub msc3391_enabled: bool, | ||
| pub msc4069_profile_inhibit_propagation: bool, | ||
| pub msc4028_push_encrypted_events: bool, | ||
| pub msc4108_enabled: bool, | ||
| pub msc4108_delegation_endpoint: Option<String>, | ||
| pub msc3575_enabled: bool, | ||
| pub msc4133_enabled: bool, | ||
| pub msc4155_enabled: bool, | ||
| pub msc4306_enabled: bool, | ||
| pub msc4169_enabled: bool, | ||
| pub msc4354_enabled: bool, | ||
| pub msc4222_enabled: bool, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this will get fixed by #19876 (comment)