fix: Embedding views with partial FK references broken

This is a regression introduced in d2719420f4.

Fixes #2548

Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
Wolfgang Walther
2022-10-31 18:15:06 +01:00
committed by Wolfgang Walther
parent b2935ef799
commit 44dd73adcc
4 changed files with 28 additions and 1 deletions
+4
View File
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
### Fixed
- #2548, Fix regression when embedding views with partial references to multi column FKs - @wolfgangwalther
## [10.1.0] - 2022-10-28
### Added
+5 -1
View File
@@ -804,6 +804,7 @@ allViewsKeyDependencies =
select
contype::text as contype,
conname,
array_length(conkey, 1) as ncol,
conrelid as resorigtbl,
col as resorigcol,
ord
@@ -815,6 +816,7 @@ allViewsKeyDependencies =
select
concat(contype, '_ref') as contype,
conname,
array_length(confkey, 1) as ncol,
confrelid,
col,
ord
@@ -980,7 +982,9 @@ allViewsKeyDependencies =
join pg_class tbl on tbl.oid = rep.resorigtbl
join pg_attribute col on col.attrelid = tbl.oid and col.attnum = rep.resorigcol
join pg_namespace sch on sch.oid = tbl.relnamespace
group by sch.nspname, tbl.relname, rep.view_schema, rep.view_name, pks_fks.conname, pks_fks.contype
group by sch.nspname, tbl.relname, rep.view_schema, rep.view_name, pks_fks.conname, pks_fks.contype, pks_fks.ncol
-- make sure we only return key for which all columns are referenced in the view - no partial PKs or FKs
having ncol = array_length(array_agg(row(col.attname, view_columns) order by pks_fks.ord), 1)
|]
param :: HE.Value a -> HE.Params a
@@ -563,3 +563,6 @@ spec =
}
]|]
{ matchHeaders = [matchContentTypeJson] }
it "should not expose hidden FKs" $
get "/va?select=vb(*)" `shouldRespondWith` 200
+16
View File
@@ -2980,3 +2980,19 @@ select parent.parent as grandparent,
join public.i2459_self_t as child
on child.parent = parent.id
where child.type = 'B';
-- issue https://github.com/PostgREST/postgrest/issues/2548
CREATE TABLE public.ta (
a1 INT PRIMARY KEY,
a2 INT,
UNIQUE (a1, a2)
);
CREATE TABLE public.tb (
b1 INT REFERENCES public.ta (a1),
b2 INT,
FOREIGN KEY (b1, b2) REFERENCES public.ta (a1, a2)
);
CREATE VIEW test.va AS SELECT a1 FROM public.ta;
CREATE VIEW test.vb AS SELECT b1 FROM public.tb;