Reputation: 785
I have an array of queries which I unite with the OR operation, Parse.Query.or. Sometimes I get the following error.
{"code":1,"error":"internal error"}
This error occurs at some requests, but not all, and I have come up with that the order of the queries affects the response (I added a shuffle method that randomly order the queries to come up with this). Logging the query order made me realize that some distinct orders makes the query execution fail and the rest works just as expected.
queries
is of type Parse.Query[]
.
queries = _.shuffle(queries);
var unionQuery = Parse.Query.or.apply(Parse.Query, queries);
unionQuery.find({ useMasterKey: true }).then(function (res) {
console.log('success');
}).fail(function (error) {
console.error(error);
});
Does the Function.prototype.apply() do something strange which will make my query fail sometimes?
Upvotes: 2
Views: 191
Reputation: 785
Replacing the line
var unionQuery = Parse.Query.or.apply(Parse.Query, queries);
with a loop that operates each query at a time, solved the problem.
var unionQuery = queries.pop();
_.each(queries, function (query) {
unionQuery = Parse.Query.or(unionQuery, query);
});
However, I have no idea why this works in contrast to the original code using the apply method.
Upvotes: 1