parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

server crash on query of nonexistent field relation

Open lucianmat opened this issue 10 years ago • 4 comments

Sending query for a relationship that has not yet registered field, it will crash the server :

Promise.resolve()
    .then(()=>{
        var object = new Parse.Object('TestObject');
        object.set('name','Named');
        return object.save()
            .then(function (rez) {
                var query =rez.relation('users').query();
                return query.find()
                        .then((users)=>{
                            console.log(users);
                        },(err)=>{
                            console.error(err);
                        });
            });
    })

It will crash with error :

Uncaught internal server error. [TypeError: Cannot read property 'match' of undefined] TypeError: Cannot read property 'match' of undefined
    at [...]/parse-server/ExportAdapter.js:108:18
    at process._tickDomainCallback (node.js:444:9)

To fix, I think that line 108 should be :

var match = t ? t.match(/^relation<(.*)>$/) : false;

(as it is in similar function reduceInRelation )

lucianmat avatar Feb 06 '16 07:02 lucianmat

Interested in submitting a PR with a test case or two?

gfosco avatar Feb 07 '16 01:02 gfosco

Sure. Added test case as have discovered, as query for Role users before adding any user to role.

lucianmat avatar Feb 07 '16 08:02 lucianmat

Not sure if this is the correct place to mention this or if I should create a new issue, but after getting this server crash I realized that there's no way to create a relation in the parse-server at least not one that's obvious to me. The docs all mention creating the relation in the data browser, but there is no data browser in the parse server any more. Suggestions?

derickito avatar Feb 19 '16 05:02 derickito

I submitted PR #861 to address this. :+1:

gfosco avatar Mar 06 '16 08:03 gfosco