fix: missing=default error msg on generated column

This commit is contained in:
steve-chavez
2023-04-27 19:27:09 -05:00
committed by Steve Chavez
parent c63786733a
commit 887948d259
4 changed files with 59 additions and 8 deletions
+26 -2
View File
@@ -13,7 +13,8 @@ import Text.Heredoc
import PostgREST.Config.PgVersion (PgVersion, pgVersion100,
pgVersion110, pgVersion112,
pgVersion130)
pgVersion120, pgVersion130,
pgVersion140)
import Protolude hiding (get)
import SpecHelper
@@ -496,7 +497,7 @@ spec actualPgVersion = do
}
when (actualPgVersion >= pgVersion100) $
it "inserts a default on a generated by default as identity column" $ do
it "inserts a default on a generated by default as identity column" $
request methodPost "/channels?columns=id,data,slug&select=data,slug" [("Prefer", "return=representation"), ("Prefer", "missing=default")]
[json| { "slug": "foo" } |]
`shouldRespondWith`
@@ -505,6 +506,29 @@ spec actualPgVersion = do
, matchHeaders = ["Preference-Applied" <:> "missing=default"]
}
when (actualPgVersion >= pgVersion120) $
it "fails with a good error message on generated always columns" $
request methodPost "/foo?columns=a,b" [("Prefer", "return=representation"), ("Prefer", "missing=default")]
[json| [
{"a": "val"},
{"a": "val", "b": "val"}
]|]
`shouldRespondWith`
(if actualPgVersion < pgVersion140
then [json| {
"code": "42601",
"details": "Column \"b\" is a generated column.",
"hint": null,
"message": "cannot insert into column \"b\""
}|]
else [json| {
"code": "428C9",
"details": "Column \"b\" is a generated column.",
"hint": null,
"message": "cannot insert a non-DEFAULT value into column \"b\""
}|])
{ matchStatus = 400 }
it "inserts json that has duplicate keys" $ do
request methodPost "/tbl_w_json" [("Prefer", "return=representation")]
[json| { "data": { "a": 1, "a": 2 }, "id": 3 } |]