Skip to content

Commit 1ef8aa4

Browse files
committed
Fix autocomplete for custom schemas
Autocomplete queries did not pass the River client's configured schema. With a non-default schema, job kind and queue name suggestions could query the wrong tables. Pass the configured schema to both driver queries so autocomplete reads from the same schema as the River client.
1 parent 1ed0f3f commit 1ef8aa4

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Global live update pause: disable automatic query refreshes on browser focus and reconnect, preventing paused workflow detail pages from re-fetching wait data outside the configured refresh interval. [PR #584](https://github.com/riverqueue/riverui/pull/584).
1313
- Job detail: preserve line breaks in attempt logs while keeping structured JSON viewer content outside preformatted code markup. [PR #592](https://github.com/riverqueue/riverui/pull/592).
14+
- Autocomplete: correctly use the River client's configured schema when querying job kinds and queue names.
1415

1516
## [v0.16.0] - 2026-05-19
1617

handler_api_endpoint.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (a *autocompleteListEndpoint[TTx]) Execute(ctx context.Context, req *autoco
114114
Exclude: req.Exclude,
115115
Match: match,
116116
Max: 100,
117+
Schema: a.Client.Schema(),
117118
})
118119
if err != nil {
119120
return nil, fmt.Errorf("error listing job kinds: %w", err)
@@ -133,6 +134,7 @@ func (a *autocompleteListEndpoint[TTx]) Execute(ctx context.Context, req *autoco
133134
Exclude: req.Exclude,
134135
Match: match,
135136
Max: 100,
137+
Schema: a.Client.Schema(),
136138
})
137139
if err != nil {
138140
return nil, fmt.Errorf("error listing queue names: %w", err)

handler_api_endpoint_test.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type setupEndpointTestBundle struct {
3131
client *river.Client[pgx.Tx]
3232
exec riverdriver.ExecutorTx
3333
logger *slog.Logger
34+
schema string
3435
tx pgx.Tx
3536
}
3637

@@ -43,10 +44,10 @@ func setupEndpointWithOpts[TEndpoint any](ctx context.Context, t *testing.T, ini
4344
t.Helper()
4445

4546
var (
46-
logger = riversharedtest.Logger(t)
47-
driver = riverpgxv5.New(riversharedtest.DBPool(ctx, t))
48-
tx, _ = riverdbtest.TestTxPgxDriver(ctx, t, driver, opts)
49-
exec = driver.UnwrapExecutor(tx)
47+
logger = riversharedtest.Logger(t)
48+
driver = riverpgxv5.New(riversharedtest.DBPool(ctx, t))
49+
tx, schema = riverdbtest.TestTxPgxDriver(ctx, t, driver, opts)
50+
exec = driver.UnwrapExecutor(tx)
5051
)
5152

5253
client, err := river.NewClient(driver, &river.Config{
@@ -72,6 +73,7 @@ func setupEndpointWithOpts[TEndpoint any](ctx context.Context, t *testing.T, ini
7273
client: client,
7374
exec: exec,
7475
logger: logger,
76+
schema: schema,
7577
tx: tx,
7678
}
7779
}
@@ -174,6 +176,35 @@ func runAutocompleteTests(t *testing.T, facet autocompleteFacet, setupFunc func(
174176
require.Len(t, resp.Data, 1)
175177
require.Equal(t, "alpha_task", *resp.Data[0])
176178
})
179+
180+
t.Run("WithCustomSchema", func(t *testing.T) {
181+
t.Parallel()
182+
183+
endpoint, bundle := setupEndpoint(ctx, t, newAutocompleteListEndpoint)
184+
client, err := river.NewClient(endpoint.Driver, &river.Config{
185+
Logger: bundle.logger,
186+
Schema: bundle.schema,
187+
})
188+
require.NoError(t, err)
189+
endpoint.Client = client
190+
191+
setupFunc(t, bundle)
192+
193+
// Ensure autocomplete uses the client's configured schema instead of the
194+
// transaction's search path.
195+
_, err = bundle.tx.Exec(ctx, "SET LOCAL search_path TO public")
196+
require.NoError(t, err)
197+
198+
resp, err := apitest.InvokeHandler(ctx, endpoint.Execute, testMountOpts(t), &autocompleteListRequest{
199+
Facet: facet,
200+
})
201+
require.NoError(t, err)
202+
require.Len(t, resp.Data, 4)
203+
require.Equal(t, "alpha_"+facet.baseString(), *resp.Data[0])
204+
require.Equal(t, "alpha_task", *resp.Data[1])
205+
require.Equal(t, "beta_"+facet.baseString(), *resp.Data[2])
206+
require.Equal(t, "gamma_"+facet.baseString(), *resp.Data[3])
207+
})
177208
}
178209

179210
func (f autocompleteFacet) baseString() string {

0 commit comments

Comments
 (0)