parse-community / Parse-Swift

The Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, Linux, Android, Windows)
https://parseplatform.org
MIT License
304 stars 69 forks source link

containedIn does not work with LiveQuery #296

Closed hajjD closed 2 years ago

hajjD commented 2 years ago

New Issue Checklist

Issue Description

containedIn query does not update LiveQuery

Steps to reproduce

Subscribe to a LiveQuery with a containedIn, will not update such as: query = query.where(containedIn(key: "parties", array: [usersProfile.id]))

But a normal equals query seems to update perfectly: query = query.where("senderID" == "VcF9fMCyKb")

Actual Outcome

Nothing, it will not update at all. Note the query containedIn loads perfectly fine when using fetch or even using the subscribedQuery but will not activate any of the events.

Environment

Client

Server

Database

Logs

When using containedIn Successfully subscribed to new query Message ({"limit":100,"skip":0,"_method":"GET","where":{"parties":{"$in":["CwyLdNXNAH"]}}}) Saved Message

When using equals to (as you can see it updates both new messages and editing old ones)

Successfully subscribed to new query Message ({"limit":100,"skip":0,"_method":"GET","where":{"senderID":"VcF9fMCyKb"}})
Saved Message
Optional([Message ({"spouseID":"CwyLdNXNAH","time":{"__type":"Date","iso":"2021-12-07T23:09:16.057Z"},"senderID":"VcF9fMCyKb","read":true,"text":"Nice","objectId":"O0rkPsUIVw","updatedAt":{"__type":"Date","iso":"2021-12-07T23:26:08.452Z"},"createdAt":{"__type":"Date","iso":"2021-12-07T23:09:16.127Z"},"parties":["VcF9fMCyKb","CwyLdNXNAH"]}), Message ({"spouseID":"CwyLdNXNAH","time":{"__type":"Date","iso":"2021-12-08T00:15:56.536Z"},"senderID":"VcF9fMCyKb","read":true,"text":"Ok wow","objectId":"KBz1yl6SHs","updatedAt":{"__type":"Date","iso":"2021-12-08T00:34:56.260Z"},"createdAt":{"__type":"Date","iso":"2021-12-08T00:15:56.639Z"},"parties":["VcF9fMCyKb","CwyLdNXNAH"]})])
Updated: Message ({"spouseID":"CwyLdNXNAH","time":{"__type":"Date","iso":"2021-12-08T00:15:56.536Z"},"senderID":"VcF9fMCyKb","read":true,"text":"Ok wow","objectId":"KBz1yl6SHs","updatedAt":{"__type":"Date","iso":"2021-12-08T00:34:56.260Z"},"createdAt":{"__type":"Date","iso":"2021-12-08T00:15:56.639Z"},"parties":["VcF9fMCyKb","CwyLdNXNAH"]})
Updated: Message ({"spouseID":"CwyLdNXNAH","time":{"__type":"Date","iso":"2021-12-07T23:09:16.057Z"},"senderID":"VcF9fMCyKb","read":true,"text":"Nice too","objectId":"O0rkPsUIVw","updatedAt":{"__type":"Date","iso":"2021-12-08T00:35:07.796Z"},"createdAt":{"__type":"Date","iso":"2021-12-07T23:09:16.127Z"},"parties":["VcF9fMCyKb","CwyLdNXNAH"]})
Entered: Message ({"spouseID":"VcF9fMCyKb","time":{"__type":"Date","iso":"2021-12-07T23:26:20.541Z"},"senderID":"VcF9fMCyKb","read":true,"text":"Cool","objectId":"gJCz7b6cIW","updatedAt":{"__type":"Date","iso":"2021-12-08T00:36:17.128Z"},"createdAt":{"__type":"Date","iso":"2021-12-07T23:26:20.635Z"},"parties":["CwyLdNXNAH","VcF9fMCyKb"]})
parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!

cbaker6 commented 2 years ago

LiveQuery doesn't support every type of query. You can see one of the newer PR's on the server that added more constraints, https://github.com/parse-community/parse-server/pull/7113 and check here for all current, https://github.com/parse-community/parse-server/blob/alpha/spec/QueryTools.spec.js. If you find something missing that you think should be added on the server, I suggest opening an issue there with a possible PR to fix. You may also want open an issue for the live query server to throw an error if a query isn’t supported. More info can be found in the LiveQuery Spec, https://github.com/parse-community/parse-server/wiki/Parse-LiveQuery-Protocol-Specification#subscribe-message

From your log:

Successfully subscribed to new query Message ({"limit":100,"skip":0,"_method":"GET","where":{"parties":{"$in":["CwyLdNXNAH"]}}}) Saved Message

The Swift SDK passes containedIn to the server correctly, meaning once the server supports this type of query it will automatically trigger events (the Swift SDK already supports this query, but the server doesn’t).

If you find containedIn not working for a regular query, your issue should then be in this repo.

lsmilek1 commented 2 years ago

Pardon additional question... Is this issue about updating the query after it is subscribed for the first time? Because I am actually using "containedIn" as per command above and it is working. I just have to unsubscribe it and subscribe again whenever I need to change the array of the criteria

hajjD commented 2 years ago

Pardon additional question... Is this issue about updating the query after it is subscribed for the first time? Because I am actually using "containedIn" as per command above and it is working. I just have to unsubscribe it and subscribe again whenever I need to change the array of the criteria

No unfortunately despite the subscription I would get zero updates/deletions etc. What version of parse server are you on?

cbaker6 commented 2 years ago

@EliteTechnicalCare you should provide more information in your question. For example, show all of your complete ParseObject's in question.

I suspect the parties field is actually of type "pointer", if so, your query isn't correct.

Also, you should check if your regular containedIn query works before trying it with LiveQuery. The examples you showed are completely different from each other and aren't checking the same property:

query = query.where(containedIn(key: "parties", array: [usersProfile.id])) query = query.where("senderID" == "VcF9fMCyKb")

For questions, you should ask here: https://community.parseplatform.org

as oppose to opening issues.

hajjD commented 2 years ago

@EliteTechnicalCare you should provide more information in your question. For example, show all of your complete ParseObject's in question.

I suspect the parties field is actually of type "pointer", if so, your query isn't correct.

parties is an Array not a pointer.

Also, you should check if your regular containedIn query works before trying it with LiveQuery. The examples you showed are completely different from each other and aren't checking the same property:

query = query.where(containedIn(key: "parties", array: [usersProfile.id])) query = query.where("senderID" == "VcF9fMCyKb")

As I specified in my original post, the query works perfectly fine, it simply doesn't auto update after the initial fetch.

For questions, you should ask here: https://community.parseplatform.org

as oppose to opening issues.

What question have I asked this entire thread?

cbaker6 commented 2 years ago

Your original post and everything after doesn’t signal there’s an actual issue. You haven’t provided enough information to elude to an issue or even replicate an issue. It seems, from your post, you are probably not setting up your queries correctly which is why this is labeled as a question. If your ask the question, “how to properly setup a live query using containedIn?” on the link I provided and provide the details of your ParseObjects and queries, you will most likely get what you need. If there happens to be a bug with correct setup, then you should open an issue.

As I specified in my original post, the query works perfectly fine, it simply doesn't auto update after the initial fetch.

Your original post looks sketchy and doesn't provide enough info as I mentioned here. Your post is better suited as a question until we can see you are querying correctly and there's in fact a real bug.

hajjD commented 2 years ago

you are probably not setting up your queries correctly

Which is why it works perfectly fine until I attempt a LiveQuery with it. I haven't asked a question, I understand how queries work. They are working perfectly fine, the only issue is when I use a query with containedIn with LiveQuery. Every other query ive tested works fine with LiveQuery. So I know how to use LiveQuery. Every time Ive used containedIn for normal queries works fine. So I know how to use containedIn. Only issue I am having is when I am using containedIn with LiveQuery.

@lsmilek1 says it works with him so the only thing I asked him was what server version he is running. I am not denying that this could very well be a server issue, but I am not here for a tutorial on how to do queries. Rather, I am trying to pin point where the issue is and report it (if need be).

I am not trying to be difficult, I have left this issue closed etc but would be good to see what server version he is running so I can move forward in the right direction.

cbaker6 commented 2 years ago

Every time Ive used containedIn for normal queries works fine. So I know how to use containedIn. Only issue I am having is when I am using containedIn with LiveQuery.

I stated here, you provided examples that are "completely different" from each other, essentially you provided an apples to oranges comparison.

Proper steps to flush out where your problem is:

  1. create a simple == query, find the results, are they correct?
  2. use the query in "1" as a live query, do you receive the proper updates?
  3. create a simple containedIn query, find the results, are they correct? (you have not provided anything that shows you have done this the entire thread, thus making it extremely hard to help you)
  4. use the query in "3" as a live query, do you receive the proper updates?

If 1,2, and 3 works and 4 doesn't, then either:

  1. LiveQuery doesn't support containedIn, or
  2. LiveQuery doesn't support containedIn in the version of the server you are using and may support it in a newer version

If 1 and 2 work, and 3 and 4 doesn't work then either:

  1. you have setup your containedIn query incorrectly
  2. there's a bug in the Swift SDK (less likely, but possible as the SDK has test cases. In addition @lsmilek1 mentioned it worked https://community.parseplatform.org/t/update-constraint-of-livequery/1866
  3. there's a bug on the server (even less likely as the server has test cases and other SDKs use this)

In any of the cases, you should be providing enough information when asking a question or opening an issue. Enough information requires providing your ParseObject's to understand your setup. In addition, you should take the debugging steps necessary to isolate your problem (1-4 above) and show the results of these steps.

cbaker6 commented 2 years ago

parties is an Array not a pointer.

parties is an array of what exactly? Your query attempts to treat it as an "array of strings", particularly containing objectId's. I ask if this is an array of "pointers" to ParseObject's because if it is, your query is incorrect. If you provided your ParseObject or what this field looks like in your Parse Dashboard, then this type of question wouldn't need to be asked

As I specified in my original post, the query works perfectly fine, it simply doesn't auto update after the initial fetch.

We will need you to provide necessary information I asked for in the previous comments to determine if it's indeed "perfectly fine."