Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when overwriting query var #1992

Closed
chaimsiegel opened this issue Jun 6, 2016 · 4 comments
Closed

error when overwriting query var #1992

chaimsiegel opened this issue Jun 6, 2016 · 4 comments

Comments

@chaimsiegel
Copy link

chaimsiegel commented Jun 6, 2016

When I ran the following cloud code on parse-server I recieved the id of the first element twice ["VYSPEFBSx4", "VYSPEFBSx4"]

var data = ['7495176386', '8042291309'];
var query = new Parse.Query("Tick"); 
var results = [];
 data.forEach(function(num){
    query.equalTo("tickID", num);
    query.first().then(function(result){
        results.push(result.id);
    });
}); 

The response should be ["VYSPEFBSx4", "EBLarI2NA1"] however it appears that the parse query was not overwritten for the second element in the loop. (This error did NOT occur on Parse.)

I finally found the solution which is to declare the parse query in the forEach loop like:

var data = ['8042291309','7495176386'];
var results = [];
 data.forEach(function(num){
    var query = new Parse.Query("Tick"); 
    query.equalTo("tickID", num);
    query.first().then(function(result){
        results.push(result.id);
    });
}); 

I did not see any mention of this error in the migration guide and thought it might be helpful

@drew-gross
Copy link
Contributor

To help us debug this, can you include the exact request and response in Parse Server? (you can see this in the logs using VERBOSE=1 environment variable)

@chaimsiegel
Copy link
Author

 parse-server-example running on port 1337.
 verbose: POST /parse/functions/initiate { host: 'localhost:1337',

   connection: 'keep-alive',
   'content-length': '199',
   'cache-control': 'max-age=0',
   origin: 'null',
   'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,
 like Gecko) Chrome/50.0.2661.102 Safari/537.36',
   'content-type': 'text/plain',
   accept: '*/*',
   'accept-encoding': 'gzip, deflate',
   'accept-language': 'he-IL,he;q=0.8,en-US;q=0.6,en;q=0.4' } {}
 verbose: GET /parse/classes/Tick { 'user-agent': 'node-XMLHttpRequest, Parse/j
 s1.8.5 (NodeJS 4.4.2)',
   accept: '*/*',
   'content-type': 'text/plain',
   host: 'localhost:1337',
   'content-length': '231',
   connection: 'close' } {
   "where": {
     "tickID": "8042291309"
   },
   "limit": 1
 }
 verbose: GET /parse/classes/Tick { 'user-agent': 'node-XMLHttpRequest, Parse/j
 s1.8.5 (NodeJS 4.4.2)',
   accept: '*/*',
   'content-type': 'text/plain',
   host: 'localhost:1337',
   'content-length': '231',
   connection: 'close' } {
   "where": {
     "tickID": "8042291309"
   },
   "limit": 1
 }
 verbose: {
   "response": {
     "results": [
       {
         "objectId": "VYSPEFBSx4",
         "lastStatusChangeDate": {
           "__type": "Date",
           "iso": "2016-06-01T14:59:22.844Z"
         }
         "user": {
           "__type": "Pointer",
           "className": "_User",
           "objectId": "zhfeJOQn8n"
         },
         "updatedAt": "2016-06-01T14:59:04.111Z",
         "createdAt": "2016-06-01T14:59:04.111Z",
       }
     ]
   }
 }
 verbose: {
   "response": {
     "results": [
       {
         "objectId": "VYSPEFBSx4",
         "lastStatusChangeDate": {
           "__type": "Date",
           "iso": "2016-06-01T14:59:22.844Z"
         },
         "user": {
           "__type": "Pointer",
           "className": "_User",
           "objectId": "zhfeJOQn8n"
         },    
         "updatedAt": "2016-06-01T14:59:04.111Z",
         "createdAt": "2016-06-01T14:59:04.111Z",
       }
     ]
   }
 }
 verbose: {
   "response": {
     "result": [
       "VYSPEFBSx4",
       "VYSPEFBSx4"
     ]
   }
 }

@chaimsiegel
Copy link
Author

chaimsiegel commented Jun 7, 2016

It appears that this also works:
var data = ['7495176386', '8042291309'];
var results = [];
var query;
data.forEach(function(num){
query = new Parse.Query("Tick");
query.equalTo("tickID", num);
query.first().then(function(result){
results.push(result.id);
});
});

The main thing is that the line query = new Parse.Query("Tick"); needs to be inside the loop to get correct results which wasn't required in Parse

@hramos
Copy link
Contributor

hramos commented Jul 27, 2016

We're closing this issue due to inactivity.

If this is a bug you care about that is not getting attention, consider opening a pull request with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants