-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move checkIsFatal logic to usePool #3524
Conversation
The fatal logic is now inside `usePool`. It centralizes the logic which is better for Locality of Behavior. Removes: - The need to do checkIsFatal on other parts of the code - SCFatalFail/ConnFatalFail states which are no longer needed.
fdda311
to
31fcf04
Compare
-- Check for a syntax error (42601 is the pg code) only for queries that don't have `WITH pgrst_source` as prefix. | ||
-- This would mean the error is on our schema cache queries, so we treat it as fatal. | ||
-- TODO have a better way to mark this as a schema cache query | ||
SQL.ServerError "42601" _ _ _ _ -> | ||
unless ("WITH pgrst_source" `BS.isPrefixOf` tpl) $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added on https://github.com/PostgREST/postgrest/pull/1685/files#diff-328c2f3103b25df9c32be37811eabc32ea0f39cea4f860b33651b3d470adf974R221. To preserve behavior I'm marking it here to only act on schema cache queries because on older pg versions 42601
also appears on API queries, in particular when inserting on generated columns.
postgrest/test/spec/Feature/Query/InsertSpec.hs
Lines 550 to 571 in d25df45
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 } |
actualPgVersion <- getPgVersion appState | ||
when (actualPgVersion < minimumPgVersion) $ do | ||
observer $ ExitUnsupportedPgVersion actualPgVersion minimumPgVersion | ||
killThread mainThreadId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coverage failing because we have no way of testing when we quit
Towards solving #3523
The fatal logic is now inside
usePool
. It centralizes the logic which is better for Locality of Behavior.Removes: