fix: request failures when work_mem is set on a role

This commit is contained in:
Laurence Isla
2026-06-03 13:45:34 -05:00
committed by Steve Chavez
parent a149405d11
commit 416a15480f
7 changed files with 47 additions and 5 deletions
@@ -582,6 +582,23 @@
pdSchema: public
pdVolatility: Volatile
- - qiName: get_work_mem
qiSchema: public
- - pdDescription: null
pdFuncSettings: []
pdHasVariadic: false
pdName: get_work_mem
pdParams: []
pdReturnType:
contents:
contents:
qiName: text
qiSchema: pg_catalog
tag: Scalar
tag: Single
pdSchema: public
pdVolatility: Volatile
- - qiName: notify_do_nothing
qiSchema: public
- - pdDescription: null
+4 -1
View File
@@ -8,11 +8,12 @@ CREATE ROLE postgrest_test_author;
CREATE ROLE postgrest_test_serializable;
CREATE ROLE postgrest_test_repeatable_read;
CREATE ROLE postgrest_test_w_superuser_settings;
CREATE ROLE postgrest_test_work_mem;
GRANT
postgrest_test_anonymous, postgrest_test_author,
postgrest_test_serializable, postgrest_test_repeatable_read,
postgrest_test_w_superuser_settings TO :"PGUSER";
postgrest_test_w_superuser_settings, postgrest_test_work_mem TO :"PGUSER";
ALTER ROLE :"PGUSER" SET pgrst.db_anon_role = 'postgrest_test_anonymous';
ALTER ROLE postgrest_test_serializable SET default_transaction_isolation = 'serializable';
@@ -23,3 +24,5 @@ ALTER ROLE postgrest_test_w_superuser_settings SET log_min_messages = 'fatal';
ALTER ROLE postgrest_test_anonymous SET statement_timeout TO '5s';
ALTER ROLE postgrest_test_author SET statement_timeout TO '10s';
ALTER ROLE postgrest_test_work_mem SET work_mem TO '3MB';
+4
View File
@@ -265,3 +265,7 @@ create or replace function custom_vary_hdr() returns void as $$
perform set_config('response.headers', '[{"Vary": "X-Test-Accept"}]', false);
end
$$ language plpgsql;
create or replace function get_work_mem() returns text as $$
select current_setting('work_mem', true);
$$ language sql;
+16
View File
@@ -2187,3 +2187,19 @@ def test_positive_pool_metric(defaultenv):
).group(1)
)
assert metrics >= 0
def test_work_mem_in_role_settings(defaultenv):
"Should work when setting work_mem on a role. See https://github.com/PostgREST/postgrest/issues/4955"
env = {
**defaultenv,
"PGRST_JWT_SECRET": SECRET,
}
headers = jwtauthheader({"role": "postgrest_test_work_mem"}, SECRET)
with run(env=env) as postgrest:
response = postgrest.session.post("/rpc/get_work_mem", headers=headers)
assert response.status_code == 200
assert response.text == '"3MB"'