diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3612a1e6e..d6b5fe24aa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #3361, Clarify PGRST204(column not found) error message - @steve-chavez - #3373, Remove rejected mediatype `application/vnd.pgrst.object+json` from response - @taimoorzaeem - #3418, Fix OpenAPI not tagging a FK column correctly on O2O relationships - @laurenceisla + - #3256, Fix wrong http status for pg error `42P17 infinite recursion` - @taimoorzaeem ## [12.0.2] - 2023-12-20 diff --git a/docs/references/errors.rst b/docs/references/errors.rst index f600100651f..1a95386889c 100644 --- a/docs/references/errors.rst +++ b/docs/references/errors.rst @@ -91,6 +91,8 @@ PostgREST translates `PostgreSQL error codes HTTP.status404 -- undefined table + "42P17" -> HTTP.status500 -- infinite recursion "42501" -> if authed then HTTP.status403 else HTTP.status401 -- insufficient privilege 'P':'T':n -> fromMaybe HTTP.status500 (HTTP.mkStatus <$> readMaybe n <*> pure m) "PGRST" -> diff --git a/test/spec/Feature/Query/QuerySpec.hs b/test/spec/Feature/Query/QuerySpec.hs index e1ce20aa12e..3b1da167b6f 100644 --- a/test/spec/Feature/Query/QuerySpec.hs +++ b/test/spec/Feature/Query/QuerySpec.hs @@ -1407,3 +1407,10 @@ spec actualPgVersion = do { matchStatus = 200 , matchHeaders = [matchContentTypeJson] } + + context "test infinite recursion error 42P17" $ + it "return http status 500" $ + get "/infinite_recursion?select=*" `shouldRespondWith` + [json|{"code":"42P17","message":"infinite recursion detected in rules for relation \"infinite_recursion\"","details":null,"hint":null}|] + { matchStatus = 500 } + diff --git a/test/spec/fixtures/schema.sql b/test/spec/fixtures/schema.sql index be677e5f2f2..7b7f84f2a33 100644 --- a/test/spec/fixtures/schema.sql +++ b/test/spec/fixtures/schema.sql @@ -3768,3 +3768,10 @@ create aggregate test.outfunc_agg (anyelement) ( , stype = "pg/outfunc" , sfunc = outfunc_trans ); + +-- https://github.com/PostgREST/postgrest/issues/3256 +create view test.infinite_recursion as +select * from test.projects; + +create or replace view test.infinite_recursion as +select * from test.infinite_recursion;