Files
synapse/rust
Erik JohnstonandClaude Opus 4.8 62f113f0a3 Fix custom-profile-field reads/writes on the Rust backend
Custom profile fields use Postgres JSON types that the shim couldn't handle, so
the ProfileFieldRestServlet returned HTTP 500 on the Rust backend. Under trial's
parallel runner these 500s also polluted their worker and cascaded into
unrelated failures, which is what made runs look non-deterministically flaky —
psycopg2 was unaffected.

Three gaps, fixed here (json/jsonb decode was added separately):

  - Bind a JSON document (as text) to a `json` / `jsonb` parameter: `?::jsonb`
    types the parameter as jsonb, so `ToSql` now encodes `Text` for `json`
    (raw text) and `jsonb`/`jsonpath` (a one-byte version header then the
    text). `set_profile_field` accordingly passes the canonical JSON as text
    rather than a psycopg2 `Json` wrapper (which the shim can't bind, and which
    coupled the storage layer to psycopg2).

  - Bind a `jsonpath` parameter: `get_profile_field`'s
    `JSONB_PATH_EXISTS(fields, ?)` types the parameter as `jsonpath`; it now
    encodes the same way as `jsonb`.

  - `JSON_BUILD_OBJECT(?, ?::jsonb)` left the key parameter's type
    indeterminate in a prepared statement (SQLSTATE 42P18) — psycopg2 sends
    untyped parameters and infers at execute, but the shim prepares. Cast the
    key to `?::text` so its type is explicit.

Fixes tests.rest.client.test_profile on the Rust backend (37/37, stable under
-j4 across repeated runs); psycopg2 and sqlite are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W3G4M92AmwSSZCbmtMJU3d
2026-07-06 10:14:31 +00:00
..