-
-
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
fix: handle queries on non-existing table gracefully #3869
base: main
Are you sure you want to change the base?
fix: handle queries on non-existing table gracefully #3869
Conversation
Add new `TableNotFound` error and add json error message for this error. Closes PostgREST#3697.
95d4973
to
52591c0
Compare
@@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |||
- #3795, Clarify `Accept: vnd.pgrst.object` error message - @steve-chavez | |||
- #3779, Always log the schema cache load time - @steve-chavez | |||
- #3706, Fix insert with `missing=default` uses default value of domain instead of column - @taimoorzaeem | |||
- #3697, Handle queries on non-existing table gracefully - @taimoorzaeem |
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.
Seeing the change in the tests output, I think this should also be listed in ### Changed
.
This also means that we should release it on the upcoming major.
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.
Does that mean you would not consider backpatching this?
Personally, I don't think this needs to be explicitly mentioned. It's an error condition that nobody relies on. This only comes up when they do something wrong - and they get a better error now. So this is hardly breaking any existing workflows, right?
(maybe I missed the relevant test output change, though - I assume it's about the 400 -> 404, from no foreign key relationship -> no table)
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.
Does that mean you would not consider backpatching this?
Yeah, I was thinking no backpatch. Just to be extra careful.
So this is hardly breaking any existing workflows, right?
I know some users that rely on table requests with no resource embedding being fast (in presence of slow relationships loads), if that has changed (test mentioned on #3869 (comment)) then it would certainly break existing workflows.
|
||
assert len(output) == 5 | ||
assert "Connection" and "is available" in output[3] | ||
assert "Connection" and "is available" in output[4] | ||
assert "Connection" and "is used" in output[5] | ||
assert "Connection" and "is used" in output[6] | ||
assert len(output) == 7 | ||
assert "Connection" and "is used" in output[4] |
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.
Hm, the change in these lines I don't understand. Why does len(output)
change from 7 to 5?
[json|{} |] | ||
[json|{"code":"PGRST205","details":null,"hint":null,"message":"Could not find relation 'test.garlic' in the schema cache"} |] |
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.
Hm, so the empty body {}
on an insert error (#3697) was tested. The behavior is a bit weird, it must have escaped review before.
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.
A quick git blame
reveals that it was introduced in #2542.
Now that we rely on the schema cache for simple table filters, we need to make sure these requests are fast when a schema cache load for relationships is slow (#3046). There's a test that validates the above behavior (a request with resource embedding is blocked until the schema cache finishes loading): postgrest/test/io/test_big_schema.py Lines 10 to 34 in 52591c0
We need an additional test that asserts that a table request (with no resource embedding) finishes in a short |
`shouldRespondWith` [json| | ||
{ "hint": null, "details":null, | ||
"code":"PGRST205", | ||
"message":"Could not find relation 'test.foozle' in the schema cache" |
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.
Do we generally leak the exposed schema name in the output? I'm not a fan, I think this should better be:
"message":"Could not find relation 'test.foozle' in the schema cache" | |
"message":"Could not find relation 'foozle' in the schema cache" |
But this might be the wrong PR to raise that, if we do it elsewhere as well.
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.
Couldn't find any tests where we do it for tables, but we do it for functions.
postgrest/test/spec/Feature/Query/RpcSpec.hs
Line 1145 in e2dd435
"message": "Could not find the function test.unnamed_int_param in the schema cache", |
@@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |||
- #3795, Clarify `Accept: vnd.pgrst.object` error message - @steve-chavez | |||
- #3779, Always log the schema cache load time - @steve-chavez | |||
- #3706, Fix insert with `missing=default` uses default value of domain instead of column - @taimoorzaeem | |||
- #3697, Handle queries on non-existing table gracefully - @taimoorzaeem |
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.
Does that mean you would not consider backpatching this?
Personally, I don't think this needs to be explicitly mentioned. It's an error condition that nobody relies on. This only comes up when they do something wrong - and they get a better error now. So this is hardly breaking any existing workflows, right?
(maybe I missed the relevant test output change, though - I assume it's about the 400 -> 404, from no foreign key relationship -> no table)
Add new
TableNotFound
error and add json errormessage for this error. Closes #3697.
(Couldn't think of a better changelog/commit message. Feel free to suggest a new/better message).