fix: handle queries on non-existing table gracefully

This commit is contained in:
Taimoor Zaeem
2025-02-21 13:49:54 -05:00
committed by GitHub
parent 9c880c082a
commit 390ba19932
13 changed files with 125 additions and 58 deletions
+31 -4
View File
@@ -7,8 +7,8 @@ from util import *
from postgrest import *
def test_requests_wait_for_schema_cache_reload(defaultenv):
"requests that use the schema cache (e.g. resource embedding) wait for the schema cache to reload"
def test_requests_with_resource_embedding_wait_for_schema_cache_reload(defaultenv):
"requests that use the schema cache with resource embedding wait long for the schema cache to reload"
env = {
**defaultenv,
@@ -34,6 +34,33 @@ def test_requests_wait_for_schema_cache_reload(defaultenv):
assert plan_dur > 10000.0
def test_requests_without_resource_embedding_wait_for_schema_cache_reload(defaultenv):
"requests that use the schema cache without resource embedding wait less for the schema cache to reload"
env = {
**defaultenv,
"PGRST_DB_SCHEMAS": "apflora",
"PGRST_DB_POOL": "2",
"PGRST_DB_ANON_ROLE": "postgrest_test_anonymous",
"PGRST_SERVER_TIMING_ENABLED": "true",
}
with run(env=env, wait_max_seconds=30) as postgrest:
# reload the schema cache
response = postgrest.session.get("/rpc/notify_pgrst")
assert response.status_code == 204
postgrest.wait_until_scache_starts_loading()
response = postgrest.session.get("/tpopmassn")
assert response.status_code == 200
plan_dur = parse_server_timings_header(response.headers["Server-Timing"])[
"plan"
]
assert plan_dur < 10000.0
# TODO: This test fails now because of https://github.com/PostgREST/postgrest/pull/2122
# The stack size of 1K(-with-rtsopts=-K1K) is not enough and this fails with "stack overflow"
# A stack size of 200K seems to be enough for succeess
@@ -65,6 +92,6 @@ def test_should_not_fail_with_stack_overflow(defaultenv):
with run(env=env, wait_max_seconds=30) as postgrest:
response = postgrest.session.get("/unknown-table?select=unknown-rel(*)")
assert response.status_code == 400
assert response.status_code == 404
data = response.json()
assert data["code"] == "PGRST200"
assert data["code"] == "PGRST205"