fix: PATCH requests not recognizing embedded filters

- Already fixed in #2618
- Adds tests and CHANGELOG
This commit is contained in:
Laurence Isla
2023-04-14 16:42:55 -05:00
committed by GitHub
parent ce378e6b3a
commit 0a2b7064c7
2 changed files with 170 additions and 85 deletions
+1
View File
@@ -50,6 +50,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
+ Fix the`"message": "syntax error at or near \"RETURNING\""` error + Fix the`"message": "syntax error at or near \"RETURNING\""` error
+ Fix doing a limited update/delete when an `order` query parameter was present + Fix doing a limited update/delete when an `order` query parameter was present
- #2742, Fix db settings and pg version queries not getting prepared - @steve-chavez - #2742, Fix db settings and pg version queries not getting prepared - @steve-chavez
- #2618, Fix `PATCH` requests not recognizing embedded filters and using the top-level resource instead - @steve-chavez
### Changed ### Changed
+89 -5
View File
@@ -382,7 +382,8 @@ spec = do
} }
context "tables with self reference foreign keys" $ do context "tables with self reference foreign keys" $ do
it "embeds children after update" $ context "embeds children after update" $ do
it "without filters" $
request methodPatch "/web_content?id=eq.0&select=id,name,web_content(name)" request methodPatch "/web_content?id=eq.0&select=id,name,web_content(name)"
[("Prefer", "return=representation")] [("Prefer", "return=representation")]
[json|{"name": "tardis-patched"}|] [json|{"name": "tardis-patched"}|]
@@ -394,7 +395,20 @@ spec = do
matchHeaders = [matchContentTypeJson] matchHeaders = [matchContentTypeJson]
} }
it "embeds parent, children and grandchildren after update" $ it "with filters" $
request methodPatch "/web_content?id=eq.0&select=id,name,web_content(name)&web_content.name=like.f*"
[("Prefer", "return=representation")]
[json|{"name": "tardis-patched"}|]
`shouldRespondWith`
[json|
[ { "id": 0, "name": "tardis-patched", "web_content": [ { "name": "fezz" }, { "name": "foo" } ]} ]
|]
{ matchStatus = 200,
matchHeaders = [matchContentTypeJson]
}
context "embeds parent, children and grandchildren after update" $ do
it "without filters" $
request methodPatch "/web_content?id=eq.0&select=id,name,web_content(name,web_content(name)),parent_content:p_web_id(name)" request methodPatch "/web_content?id=eq.0&select=id,name,web_content(name,web_content(name)),parent_content:p_web_id(name)"
[("Prefer", "return=representation")] [("Prefer", "return=representation")]
[json|{"name": "tardis-patched-2"}|] [json|{"name": "tardis-patched-2"}|]
@@ -415,7 +429,28 @@ spec = do
matchHeaders = [matchContentTypeJson] matchHeaders = [matchContentTypeJson]
} }
it "embeds children after update without explicitly including the id in the ?select" $ it "with filters" $
request methodPatch "/web_content?id=eq.0&select=id,name,web_content(name,web_content(name)),parent_content:p_web_id(name)&web_content.name=like.f*&web_content.web_content.id=eq.4&parent_content.name=neq.wat"
[("Prefer", "return=representation")]
[json|{"name": "tardis-patched-2"}|]
`shouldRespondWith`
[json| [
{
"id": 0,
"name": "tardis-patched-2",
"parent_content": null,
"web_content": [
{ "name": "fezz", "web_content": [ { "name": "wut" } ] },
{ "name": "foo", "web_content": [] }
]
}
] |]
{ matchStatus = 200,
matchHeaders = [matchContentTypeJson]
}
context "embeds children after update without explicitly including the id in the ?select" $ do
it "without filters" $
request methodPatch "/web_content?id=eq.0&select=name,web_content(name)" request methodPatch "/web_content?id=eq.0&select=name,web_content(name)"
[("Prefer", "return=representation")] [("Prefer", "return=representation")]
[json|{"name": "tardis-patched"}|] [json|{"name": "tardis-patched"}|]
@@ -427,7 +462,21 @@ spec = do
matchHeaders = [matchContentTypeJson] matchHeaders = [matchContentTypeJson]
} }
it "embeds an M2M relationship plus parent after update" $ it "with filters" $
request methodPatch "/web_content?id=eq.0&select=name,web_content(name)&web_content.name=like.b*"
[("Prefer", "return=representation")]
[json|{"name": "tardis-patched"}|]
`shouldRespondWith`
[json|
[ { "name": "tardis-patched", "web_content": [ { "name": "bar" } ]} ]
|]
{ matchStatus = 200,
matchHeaders = [matchContentTypeJson]
}
context "tables with foreign keys referencing other tables" $ do
context "embeds an M2M relationship plus parent after update" $ do
it "without filters" $
request methodPatch "/users?id=eq.1&select=name,tasks(name,project:projects(name))" request methodPatch "/users?id=eq.1&select=name,tasks(name,project:projects(name))"
[("Prefer", "return=representation")] [("Prefer", "return=representation")]
[json|{"name": "Kevin Malone"}|] [json|{"name": "Kevin Malone"}|]
@@ -447,7 +496,27 @@ spec = do
matchHeaders = [matchContentTypeJson] matchHeaders = [matchContentTypeJson]
} }
it "embeds an O2O relationship after update" $ do it "with filters" $
request methodPatch "/users?id=eq.1&select=name,tasks(name,project:projects(name))&tasks.name=ilike.code*&tasks.project.name=like.*10"
[("Prefer", "return=representation")]
[json|{"name": "Kevin Malone"}|]
`shouldRespondWith`
[json|[
{
"name": "Kevin Malone",
"tasks": [
{ "name": "Code w7", "project": null },
{ "name": "Code w10", "project": { "name": "Windows 10" } }
]
}
]|]
{ matchStatus = 200,
matchHeaders = [matchContentTypeJson]
}
context "embeds an O2O relationship after update" $ do
it "without filters" $ do
request methodPatch "/students?id=eq.1&select=name,students_info(address)" request methodPatch "/students?id=eq.1&select=name,students_info(address)"
[("Prefer", "return=representation")] [("Prefer", "return=representation")]
[json|{"name": "Johnny Doe"}|] [json|{"name": "Johnny Doe"}|]
@@ -475,6 +544,21 @@ spec = do
matchHeaders = [matchContentTypeJson] matchHeaders = [matchContentTypeJson]
} }
it "with filters" $ do
request methodPatch "/students?id=eq.1&select=name,students_info(address)&students_info.code=like.0002"
[("Prefer", "return=representation")]
[json|{"name": "Johnny Doe"}|]
`shouldRespondWith`
[json|[
{
"name": "Johnny Doe",
"students_info": null
}
]|]
{ matchStatus = 200,
matchHeaders = [matchContentTypeJson]
}
context "table with limited privileges" $ do context "table with limited privileges" $ do
it "succeeds updating row and gives a 204 when using return=minimal" $ it "succeeds updating row and gives a 204 when using return=minimal" $
request methodPatch "/app_users?id=eq.1" request methodPatch "/app_users?id=eq.1"