From 3b60b7345ad7496cbbc7413eed196c88700d7ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C5=82eczek?= Date: Mon, 4 May 2026 09:01:47 +0200 Subject: [PATCH] fix: Do not clear the schema cache during retries retryingSchemaCacheLoad should not clear existing schema cache upon failure - there is no reason to do that. If there is a communication issue with the database server or db is down, clients are going to get 502 anyway. If it was a glitch when loading the schema cache - the clients are going to use old (stale) schema cache for some time until next retry re-loads it successfully. --- CHANGELOG.md | 1 + src/PostgREST/AppState.hs | 1 - test/io/fixtures/roles.sql | 2 ++ test/io/test_io.py | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c8193140a..9c401a451e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. From versio - Remove automatic transaction retries on `40001 (serialization_failure)` errors to prevent replication lag by @laurenceisla in #3673 - Fix unexpected results when embedding and filtering the same table more than once by @laurenceisla in #4075 - Fix race condition in pool_available metric causing negative values during network instability by @mkleczek in #4622 +- PostgREST no longer returns voids schema cache during loading retries by @mkleczek in #4873 #4869 ### Changed diff --git a/src/PostgREST/AppState.hs b/src/PostgREST/AppState.hs index fdaac1a908..8462ce1de0 100644 --- a/src/PostgREST/AppState.hs +++ b/src/PostgREST/AppState.hs @@ -347,7 +347,6 @@ retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThrea case result of Left e -> do markSchemaCachePending appState - putSchemaCache appState Nothing observer $ SchemaCacheErrorObs configDbSchemas configDbExtraSearchPath e return Nothing diff --git a/test/io/fixtures/roles.sql b/test/io/fixtures/roles.sql index 61070d7a1e..4ead2d2fa8 100644 --- a/test/io/fixtures/roles.sql +++ b/test/io/fixtures/roles.sql @@ -14,6 +14,8 @@ GRANT postgrest_test_serializable, postgrest_test_repeatable_read, postgrest_test_w_superuser_settings TO :"PGUSER"; +GRANT postgrest_test_anonymous TO timeout_authenticator; + ALTER ROLE :"PGUSER" SET pgrst.db_anon_role = 'postgrest_test_anonymous'; ALTER ROLE postgrest_test_serializable SET default_transaction_isolation = 'serializable'; ALTER ROLE postgrest_test_repeatable_read SET default_transaction_isolation = 'REPEATABLE READ'; diff --git a/test/io/test_io.py b/test/io/test_io.py index aa3e923dcd..70a3a1a308 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -745,7 +745,7 @@ def test_admin_ready_includes_schema_cache_state(defaultenv, metapostgrest): env = { **defaultenv, "PGUSER": role, - "PGRST_DB_ANON_ROLE": role, + "PGRST_DB_ANON_ROLE": "postgrest_test_anonymous", "PGRST_INTERNAL_SCHEMA_CACHE_QUERY_SLEEP": "500", } @@ -763,7 +763,7 @@ def test_admin_ready_includes_schema_cache_state(defaultenv, metapostgrest): assert response.status_code == 503 response = postgrest.session.get("/projects", timeout=1) - assert response.status_code == 503 + assert response.status_code == 200 reset_statement_timeout(metapostgrest, role)