Skip to content

Commit

Permalink
fix: fix wrong 503 Service Unavailable on pg error 53400
Browse files Browse the repository at this point in the history
  • Loading branch information
taimoorzaeem committed Apr 8, 2024
1 parent 5ab317c commit 92a48d9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #3340, Log when the LISTEN channel gets a notification - @steve-chavez
- #3345, Fix in-database configuration values not loading for `pgrst.server_trace_header` and `pgrst.server_cors_allowed_origins` - @laurenceisla
- #3361, Clarify PGRST204(column not found) error message - @steve-chavez
- #3267, Fix wrong `503 Service Unavailable` on pg error `53400` - @taimoorzaeem

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion src/PostgREST/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pgErrorStatus authed (SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ResultError
'3':'9':_ -> HTTP.status500 -- external routine invocation
'3':'B':_ -> HTTP.status500 -- savepoint exception
'4':'0':_ -> HTTP.status500 -- tx rollback
'5':'3':_ -> HTTP.status503 -- insufficient resources
'5':'3':_ -> HTTP.status500 -- insufficient resources
'5':'4':_ -> HTTP.status413 -- too complex
'5':'5':_ -> HTTP.status500 -- obj not on prereq state
'5':'7':'P':'0':'1':_ -> HTTP.status503 -- terminating connection due to administrator command
Expand Down
6 changes: 6 additions & 0 deletions test/spec/Feature/Query/RpcSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,3 +1466,9 @@ spec actualPgVersion =
get "/rpc/raise_sqlstate_missing_details" `shouldRespondWith`
[json|{"code":"PGRST121","message":"The message and detail field of RAISE 'PGRST' error expects JSON","details":null,"hint":null}|]
{ matchStatus = 500 }

context "test function temp_file_limit" $
it "should return http status 500" $
get "/rpc/temp_file_limit" `shouldRespondWith`
[json|{"code":"53400","message":"temporary file size exceeds temp_file_limit (1024kB)","details":null,"hint":null}|]
{ matchStatus = 500 }
2 changes: 2 additions & 0 deletions test/spec/fixtures/privileges.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ REVOKE EXECUTE ON FUNCTION privileged_hello(text) FROM PUBLIC; -- All functions
GRANT EXECUTE ON FUNCTION privileged_hello(text) TO postgrest_test_author;

GRANT USAGE ON SCHEMA test TO postgrest_test_default_role;

GRANT SET ON PARAMETER temp_file_limit TO postgrest_test_anonymous;
5 changes: 5 additions & 0 deletions test/spec/fixtures/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3759,3 +3759,8 @@ create aggregate test.outfunc_agg (anyelement) (
, stype = "pg/outfunc"
, sfunc = outfunc_trans
);

create or replace function temp_file_limit()
returns bigint as $$
select COUNT(*) FROM generate_series('-infinity'::TIMESTAMP, 'epoch'::TIMESTAMP, INTERVAL '1 DAY');
$$ language sql security definer set temp_file_limit to '1kB';

0 comments on commit 92a48d9

Please sign in to comment.