From 8b63ea82ec77e8303861ca6b7540469b86376c29 Mon Sep 17 00:00:00 2001 From: Taimoor Zaeem Date: Wed, 14 May 2025 18:25:00 +0500 Subject: [PATCH] test: add test for duplicate entries in pg_description with same OID --- test/spec/Feature/Query/ErrorSpec.hs | 4 ++-- test/spec/Feature/Query/RpcSpec.hs | 8 ++++++++ test/spec/fixtures/schema.sql | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/test/spec/Feature/Query/ErrorSpec.hs b/test/spec/Feature/Query/ErrorSpec.hs index 1c7bb3e20..da6f9cb82 100644 --- a/test/spec/Feature/Query/ErrorSpec.hs +++ b/test/spec/Feature/Query/ErrorSpec.hs @@ -42,10 +42,10 @@ pgErrorCodeMapping = do it "works with SchemaCache error" $ get "/non_existent_table" `shouldRespondWith` - [json| {"code":"PGRST205","details":null,"hint":"Perhaps you meant the table 'test.json_table'","message":"Could not find the table 'test.non_existent_table' in the schema cache"} |] + [json| {"code":"PGRST205","details":null,"hint":"Perhaps you meant the table 'test.collision_test_table'","message":"Could not find the table 'test.non_existent_table' in the schema cache"} |] { matchStatus = 404 , matchHeaders = [ "Proxy-Status" <:> "PostgREST; error=PGRST205" - , "Content-Length" <:> "172" ] + , "Content-Length" <:> "182" ] } it "works with Jwt error" $ do diff --git a/test/spec/Feature/Query/RpcSpec.hs b/test/spec/Feature/Query/RpcSpec.hs index 886791110..b78c2de9e 100644 --- a/test/spec/Feature/Query/RpcSpec.hs +++ b/test/spec/Feature/Query/RpcSpec.hs @@ -1450,3 +1450,11 @@ spec = { matchStatus = 200 , matchHeaders = [matchContentTypeJson] } + + context "schema cache duplicate definitions when two entries in pg_description have the same OID" $ + it "doesn't err with 300 Multiple Choices" $ + request methodGet "/rpc/collision_test_func?id=1" + [] "" + `shouldRespondWith` + [json| 1 |] + { matchStatus = 200 } diff --git a/test/spec/fixtures/schema.sql b/test/spec/fixtures/schema.sql index 0b22b7e3d..2254efa07 100644 --- a/test/spec/fixtures/schema.sql +++ b/test/spec/fixtures/schema.sql @@ -3800,3 +3800,18 @@ create table factory_buildings ( factory_id int references factories(id), inspections jsonb ); + +-- collision test as occured in https://github.com/PostgREST/postgrest/issues/4052 +create table test.collision_test_table (id integer); +comment on table collision_test_table is 'foobarbaz'; + +create function test.collision_test_func(id integer) +returns int language sql as $$ + select 1; +$$; + +update pg_proc +set oid = 'test.collision_test_table'::regclass::oid +where oid = 'test.collision_test_func'::regproc::oid; + +comment on function test.collision_test_func(id integer) is 'fizzbuzz';