I'm running into an issue where I present a view and try to execute fetchAllIfNeededInBackground on a few objects. The first time the function is called, I get the mentioned error. Subsequent calls yields results.
Important note to make. This pointers in the "recentSearches" array can be from two classes.
func getUserRecentSearches() {
guard let currentUser = PFUser.currentUser() else { return }
if let currentUserRecentSearches = currentUser["recentSearches"] as? [PFObject] {
PFObject.fetchAllIfNeededInBackground(currentUserRecentSearches) { (currentUserRecentSearches, error) in
if let currentUserRecentSearches = currentUserRecentSearches as? [PFObject] {
self.recentSearches = currentUserRecentSearches
self.tableView.reloadData()
}
}
}
}
It doesn't trigger the assertion below so objectId != nil
PFParameterAssert(object.objectId != nil,
@"All objects must exist on the server.");
Additionally I followed the call stack a little and it seems to indicate 6 elements but only 5 objectIds. So it seems to fail on one but returns nothing? It should return at least 5.
That one object is probably of a different class (PFUser vs a PFObject

More notes:
@nlutsenko I would appreciate your input on this. This maybe tied to #984 where I removed the assertion to be able to fetch from multiple classes at the same time.
My two guesses:
seems like this is similar to my issue
@shiva-wal don't do that, don't hijack this thread
Please remove your comment. And instead add details your issue.
I think my issue is related to yours, hopefully we come up with a fix, spent all day trying to work out whats wrong, mine seems to be with relationships and fetchIfNeededInBackgroundWithBlock
Hey everyone,
What seems to be happening is that you are trying to fetch 6 objects, where only 5 have were found on the server. We explicitly fail with an error on that one and the entire task is treated as faulted (even though the 5 objects were successfully refreshed).
The first thing I would suggest checking is whether you can reproduce the same weird behavior with a simple curl request to isolate whether the issue is on the client or on the server (my gut says it's on the server). Also, enabling logging on the server could help observe whether a client makes the proper request.
Let me know what you find from the step above ^.
Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.
Please try the latest SDK. Our release notes have details about what issues were fixed in each release.
In addition, you might find the following resources helpful:
@nlutsenko Thanks for the response. Regarding your points,
Do you have an idea why a second call to fetchAllIfNeededInBackground the exact same data yields results?
The results the second time around seem to be cached, likely from the first time around.

Based on the function above, we use the first objectId to determine the query class, can it be the cause? Since I have one pointer of a different class? if so, my question above would still be valid.
Just to point out, if I do the following on first call, the results appear from the get-go. Thats obviously because my call includes itself. So the first call is actually 2 calls in one.
func getUserRecentSearches() {
guard let currentUser = PFUser.currentUser() else { return }
if let currentUserRecentSearches = currentUser["recentSearches"] as? [PFObject] {
PFObject.fetchAllIfNeededInBackground(currentUserRecentSearches) { (currentUserRecentSearches, error) in
if let currentUserRecentSearches = currentUserRecentSearches as? [PFObject] {
self.recentSearches = currentUserRecentSearches
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
}
self.getUserRecentSearches()
}
}
}
This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.
We are closing this issue due to another 7 days of inactivity. If you have additional information to help pinpoint this issue as an SDK bug, please reopen it with the additional information.Thank you for your feedback.
There is at least one object that is of a different class (PFUser) than the rest, that may explain why the fetch seems to only find 5.
Yes and the code snipped you provided will run the query against the className of the first object, therefore marking the whole task as failed.