Skip to content
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 query select and exclude #88

Merged
merged 11 commits into from
Mar 8, 2021
Merged

Fix query select and exclude #88

merged 11 commits into from
Mar 8, 2021

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented Mar 2, 2021

Fix #86 select and exclude parse-community/parse-server#7242

  • Add variadic version of exclude
  • select and exclude example in playground
  • Ensure thread-safe endpoint is used for queries
  • Modify fetch include to use an encoded array instead of join array
  • Improve test cases select, exclude, and fetch include

@codecov
Copy link

codecov bot commented Mar 2, 2021

Codecov Report

Merging #88 (baa47d7) into main (65bfd41) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
+ Coverage   78.73%   78.75%   +0.02%     
==========================================
  Files          63       63              
  Lines        5041     5042       +1     
==========================================
+ Hits         3969     3971       +2     
+ Misses       1072     1071       -1     
Impacted Files Coverage Δ
Sources/ParseSwift/API/API+Commands.swift 82.53% <100.00%> (-0.05%) ⬇️
Sources/ParseSwift/Objects/ParseInstallation.swift 82.18% <100.00%> (-0.04%) ⬇️
Sources/ParseSwift/Objects/ParseUser.swift 76.10% <100.00%> (-0.05%) ⬇️
Sources/ParseSwift/Types/Query.swift 90.71% <100.00%> (+0.10%) ⬆️
Sources/ParseSwift/Objects/ParseObject.swift 76.23% <0.00%> (+0.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65bfd41...9f80e7e. Read the comment docs.

@cbaker6 cbaker6 marked this pull request as draft March 2, 2021 22:55
@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 2, 2021

@dplewis there's a problem here that you may know how to solve quicker than me debugging code on the server-side that I'm unfamiliar with. Query select and exclude are not working as expected as the Parse Server is returning all keys. It almost seems like it's ignoring the arrays I send for keys and excludeKeys, respectively (the server returns the whole object). I don't think this is necessarily a bug on the server-side when using GET as I see there are tests that pass for this.

My guess at the problem has something to do with the use of POST instead of GET and putting everything related to the query (besides the endpoint) in the body. When posting the query, it includes _method = "GET", which I believe overrides the POST at the server level based on https://github.com/parse-community/parse-server/blob/e6ac3b6932186a6a85601c65143305f86f63e948/src/middlewares.js#L336-L343

All other queries (first, hint, explain, etc.) I've tested work using POST for query. When using select with a simple query, var query2 = GameScore.query().select(["yolo"]), what gets sent in the body to the server is

["_method": "GET", "skip": 0, "limit": 100, "where": [:], "keys": ["yolo"]]

Note that, using find which sets limit = 1 works. Am I doing something wrong here? From what I see on the server-side, https://github.com/parse-community/parse-server/blob/e53b6c2f87b209e5b6a459f64111995caee3b7b9/src/RestQuery.js#L100-L116

when using select, keys should be at the same level as limit. When it comes to exclude, excludeKeys should be at the same level as limit as well. Is that correct?

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 3, 2021

@dplewis @pmmlo I think found the issue and it's looking to be server side. It also looks like the test cases written for this is missing a corner case. I'll update with my reasoning after some more testing

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 3, 2021

False alarm, I still don’t know where the issue is at

@pmmlo
Copy link
Contributor

pmmlo commented Mar 4, 2021

Thanks for looking into this @cbaker6 Is there any documentation on how requests should be constructed for the server? Otherwise, I could take a look at one of the other SDKs.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 5, 2021

No documentation that I know of besides how to use it in JS SDK, which which is I tried to create the current implementation from. I couldn't find this in the REST documentation. The JS SDK has it.

The iOS SDK has selectedKeys, but it looks like it's doing a standard query and then stripping the non selected keys on the client side.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 5, 2021

@pmmlo the last commit I made works by using a join of the array and turning it into a string before it goes to the server, implying that the Parse server doesn't like they way keys and excludeKeys are being encoded.

The test failures are due them still looking for arrays instead of a joined array string. If you want something that works, you can use that commit until I figure out what the actual issue is

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 5, 2021

@dplewis @mtrezza so I believe my false alarm mentioned earlier was actually a real one and the problem is server side.

In short, the keys and excludeKeys on the server are not digesting actual JSON arrays, ["yolo", ...], but instead digesting "yolo", .... Somehow JS treats both of these the same (I say this because the fixed PR I have for the server works with just removing 1 test case, more on this in the PR), but the server doesn't like it the way the Swift JSON encoder sends it, ["yolo", ...]. Note that this is the native JSON encoder and not the custom one used here for ParseObjects, so if it was encoding arrays incorrectly I'm sure it would have been caught awhile ago.

I'll submit the PR now so you the changes. I'm still running one more additional test locally to verify somethings

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 5, 2021

Done with my local tests with this framework and the server changes and they work. It looks like the tests pass on the server side and on this client SDK.

Of course, if there's a test on the JS SDK that used select([]), it will break if the server side PR is accepted. I'm guessing the other select and exclude tests will pass though

@cbaker6 cbaker6 marked this pull request as ready for review March 5, 2021 05:25
@cbaker6 cbaker6 requested a review from TomWFox March 5, 2021 05:25
@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 5, 2021

@TomWFox can you review the doc comments I added? There was a missing instance method for exclude.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 5, 2021

@pmmlo If you use docker and need a working server with this now, you can use my image, netreconlab/parse-server:latest https://hub.docker.com/repository/docker/netreconlab/parse-server

Otherwise, you will have to see what comes of the discussion and PR on the server repo

@pmmlo
Copy link
Contributor

pmmlo commented Mar 6, 2021

If you use docker and need a working server with this now, you can use my image, netreconlab/parse-server:latest https://hub.docker.com/repository/docker/netreconlab/parse-server

Thanks for all the contribs @cbaker6 I am still playing around with Parse to see if it would be good for personal use. Really solid work!

@cbaker6
Copy link
Contributor Author

cbaker6 commented Mar 6, 2021

@pmmlo thanks for discovering the bug! Definitely let us know if you find anything else.

I did find documentation on keys and excludeKeys. It highlights the issues which requires the bug fix https://docs.parseplatform.org/rest/guide/#query-constraints

Also, it looks like you may be testing/adding code in Playgrounds, if you add more examples in the playgrounds that currently aren’t there and would like to submit PRs for them, we would welcome it!

Co-authored-by: Tom Fox <13188249+TomWFox@users.noreply.github.com>
@cbaker6 cbaker6 merged commit 0ac301b into main Mar 8, 2021
@cbaker6 cbaker6 deleted the testingSelect branch March 8, 2021 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.select() in finds and firsts does not seem to exclude any fields
3 participants