You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Called relation() on non-relation field even when field is relation. #1112
I've noticed this bug on several occasions since upgrading to 2.2.0. It tends to happen after the object has been saved.
Uncaught internal server error. [Error: Called relation() on non-relation field following] Error: Called relation() on non-relation field following
at ParseUser.relation (/Users/~/Documents/github/~/node_modules/parse/lib/node/ParseObject.js:579:17)
Tried with Parse SDK 1.7.1 and 1.8.1. Anyone else experiencing this issue?
Sure thing - The following is the simplest cloud function which fails:
/**
* @CloudFunction Follow User
*
* Adds user to currentUser' 'following'
* relation,
* Sets Jobs to handle follow stats and
* followed user's follower's relation.
*
* param {String} userIdToFollow
*/
module.exports.followUser = function (request, response) {
var currentUser = request.user,
userIdToFollow = request.params.userIdToFollow,
userToFollow = new Parse.User();
if (!currentUser && request.params.currentUserId) {
currentUser = new Parse.User();
currentUser.id = request.params.currentUserId;
}
if (!currentUser) {
return response.error("You must be logged in.");
}
if (!userIdToFollow) {
return response.error("Please send a userIdToFollow.");
}
userToFollow.id = userIdToFollow;
currentUser.relation('following').add(userToFollow); // this works
currentUser.saveAsUser(currentUser)
.then(function () {
currentUser.relation('following'); // This fails (it's no longer needed here as I've refactored the code, but the error is still an issue in other more complicated functions
return Parse.Promise.when(
UserEvent.newEvent('followed', userToFollow, currentUser),
JobQueue.createJob(JobQueue.jobs.postFollowProcessing, {
user: currentUser,
userFollowed: userToFollow
}, JobQueue.priorityLevel.high)
);
})
.then(function (userEvent) {
response.success({
userEvent: userEvent
});
}, function (error) {
response.error(error);
});
};
I've just confirmed that the error subsides when I revert from 2.2.0 down to 2.1.6.
Activity
gfosco commentedon Mar 20, 2016
What is in the _SCHEMA collection record for this class & key?
omairvaiyani commentedon Mar 21, 2016
@gfosco
It's for _User
Calling
user.relation('followers')works fine until the object is saved, after which it says thatfollowers is a non-relation field.gfosco commentedon Mar 21, 2016
Can you provide additional code... where are you calling it twice?.. Writing a failing test case would really be valuable here.
omairvaiyani commentedon Mar 21, 2016
Sure thing - The following is the simplest cloud function which fails:
I've just confirmed that the error subsides when I revert from
2.2.0down to2.1.6.flovilmart commentedon Apr 1, 2016
what's that
.saveAsUserfunction?omairvaiyani commentedon Apr 2, 2016
Hi @flovilmart, it's a helper function:
omairvaiyani commentedon Apr 8, 2016
Excellent, thank you! This was stopping me from upgrading past 2.1.6!
borekwa commentedon May 18, 2016
Hey @flovilmart, I'm experiencing a similar issue to this one, as are some other users. See this issue. any thoughts?