diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d8b0310..14a2e1de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #2077, Fix `is` not working with upper or mixed case values like `NULL, TrUe, FaLsE` - @steve-chavez - #2024, Fix schema cache loading when views with XMLTABLE and DEFAULT are present - @wolfgangwalther - #1724, Fix wrong CORS header Authentication -> Authorization - @wolfgangwalther + - #2107, Clarify error for failed schema cache load. - @steve-chavez + + From `Database connection lost. Retrying the connection` to `Could not query the database for the schema cache. Retrying.` ## [9.0.0] - 2021-11-25 diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index 62dfd7ac3..f7c13d3e8 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -191,7 +191,7 @@ postgrestResponse conf maybeDbStructure jsonDbS pgVer pool time req = do Just dbStructure -> return dbStructure Nothing -> - throwError Error.ConnectionLostError + throwError Error.NoSchemaCacheError apiRequest@ApiRequest{..} <- liftEither . mapLeft Error.ApiRequestError $ diff --git a/src/PostgREST/Error.hs b/src/PostgREST/Error.hs index c3fc8c3a8..9dd737d4b 100644 --- a/src/PostgREST/Error.hs +++ b/src/PostgREST/Error.hs @@ -280,7 +280,7 @@ data Error = GucHeadersError | GucStatusError | BinaryFieldError ContentType - | ConnectionLostError + | NoSchemaCacheError | PutMatchingPkError | PutRangeNotAllowedError | JwtTokenMissing @@ -294,7 +294,7 @@ instance PgrstError Error where status GucHeadersError = HTTP.status500 status GucStatusError = HTTP.status500 status (BinaryFieldError _) = HTTP.status406 - status ConnectionLostError = HTTP.status503 + status NoSchemaCacheError = HTTP.status503 status PutMatchingPkError = HTTP.status400 status PutRangeNotAllowedError = HTTP.status400 status JwtTokenMissing = HTTP.status500 @@ -317,8 +317,8 @@ instance JSON.ToJSON Error where "message" .= ("response.status guc must be a valid status code" :: Text)] toJSON (BinaryFieldError ct) = JSON.object [ "message" .= ((T.decodeUtf8 (ContentType.toMime ct) <> " requested but more than one column was selected") :: Text)] - toJSON ConnectionLostError = JSON.object [ - "message" .= ("Database connection lost. Retrying the connection." :: Text)] + toJSON NoSchemaCacheError = JSON.object [ + "message" .= ("Could not query the database for the schema cache. Retrying." :: Text)] toJSON PutRangeNotAllowedError = JSON.object [ "message" .= ("Range header and limit/offset querystring parameters are not allowed for PUT" :: Text)] diff --git a/test/io-tests/test_io.py b/test/io-tests/test_io.py index 9a16380f9..ed6c0b55a 100644 --- a/test/io-tests/test_io.py +++ b/test/io-tests/test_io.py @@ -787,12 +787,17 @@ def test_admin_ready_includes_schema_cache_state(defaultenv): "/rpc/no_schema_cache_for_limited_authenticator" ) assert response.status_code == 200 + # force a reconnection so the new role setting is picked up postgrest.process.send_signal(signal.SIGUSR1) time.sleep(0.1) + response = postgrest.admin.get("/ready") assert response.status_code == 503 + response = postgrest.session.get("/projects") + assert response.status_code == 503 + def test_admin_not_found(defaultenv): "Should get a not found from a undefined endpoint on the admin server"