parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.94k stars 4.78k forks source link

TypeError: Cannot increment a non-numeric value. #6678

Closed lybaiyy123 closed 4 years ago

lybaiyy123 commented 4 years ago

Issue Description

js-sdk https://unpkg.com/parse@2.12.0/dist/parse.min.js decrement and increment throw Uncaught (in promise) TypeError: Cannot increment a non-numeric value.

Steps to reproduce

var g=new Parse.Object('goods') g.id='fFmIioVyHd' g.decrement('num',1) g.save().then(data=>{console.log(data)},e=>(err(e)))

Data exists on the server and the field 'num' is Number but client throw Uncaught (in promise) TypeError: Cannot increment a non-numeric value. also when i use g.decrement('num',10) report the same error There is a chance of reporting an error,

Expected Results

no error

Actual Outcome

g.decrement('num',1) g.save().then(data=>{console.log(data)},e=>(err(e))) Promise {} VM536:2 l {id: "fFmIioVyHd", _localId: undefined, _objCount: 1608, className: "goods"} parse.min.js:13 Uncaught (in promise) TypeError: Cannot increment a non-numeric value. at n.value (parse.min.js:13) at Object.r.estimateAttributes (parse.min.js:13) at Object.r.estimateAttributes (parse.min.js:13) at l.get (parse.min.js:13) at l.value (parse.min.js:13) at Object.ee [as matchesQuery] (parse.min.js:13) at parse.min.js:13 at Array.map () at f. (parse.min.js:13) at f (parse.min.js:13)

save operation send to the server and data is right

Environment Setup

Logs/Trace

JeromeDeLeon commented 4 years ago

Kindly fill out the environment setup.

JeromeDeLeon commented 4 years ago

I have tried it with parse-dashboard 2.1.0 and worked just fine. Make sure you have the latest version of client SDK and server.

image

lybaiyy123 commented 4 years ago

Kindly fill out the environment setup. client sdk https://unpkg.com/parse@2.12.0/dist/parse.min.js server "dependencies": { "express": "^4.17.1", "graphql": "^14.6.0", "parse": "^2.12.0", "parse-dashboard": "^2.0.5", "parse-server": "^4.1.0", "redis":"^3.0.2" }

when i try other class to decrement / increment ,itis ok。 so,i donot know why the client throw the uncaught error...

mtrezza commented 4 years ago

The fact that it says TypeError indicates that the current value of num is NaN.

Keep in mind that null is a value, it does not mean that there is no value set. The left field has value null which cannot be incremented, the right field has no value defined which can be incremented because it is treated as 0: image

lybaiyy123 commented 4 years ago

The fact that it says TypeError indicates that the current value of num is NaN.

  • Check whether the column is really of type Number in the Parse Dashboard
  • Check what the current value of num is directly in the database. -.- iam sure the column is 'Number', goods
mtrezza commented 4 years ago

You wrote:

when i try other class to decrement / increment ,itis ok。

lybaiyy123 commented 4 years ago

You wrote:

when i try other class to decrement / increment ,itis ok。

  • Does it only affect this class or only this object fFmIioVyHd?
  • If you create a new column num_test in Parse Dashboard and without setting any value, you try to increment it, does it work?
  1. i have try other class ,itis ok,
  2. try this class,other objetc ,itis wrong,
  3. object 'fFmIioVyHd' ,but ACL public read + write,its not work. 4.when i g.save(null,{useMasterKey:true}), itis ok.
mtrezza commented 4 years ago

Maybe the schema is corrupted, can you post it here?

If you create a new class with num column and you try to increment it, does it work?

lybaiyy123 commented 4 years ago

Maybe the schema is corrupted, can you post it here?

If you create a new class with num column and you try to increment it, does it work?

sch

lybaiyy123 commented 4 years ago

Maybe the schema is corrupted, can you post it here?

If you create a new class with num column and you try to increment it, does it work?

1.other class ,column 'num' to increment it,its ok.. 2.new class,column 'num' to increment it,its ok.. new

mtrezza commented 4 years ago

This looks like a data inconsistency somewhere.

lybaiyy123 commented 4 years ago
  • Did you manually manipulate data, schema or anything else in the database at some point?
  • Did you try to create a new column num_test and increment it?
  • Would recreating the class solve the issue?
  1. I dont update schema ,just in the parse-dashboard to change value.
  2. create a new column num_test and increment its ok,
  3. delete this class and recreat, solve the issue...
mtrezza commented 4 years ago

Glad to hear the issue is solved.

lybaiyy123 commented 4 years ago

But the reason was not found

mtrezza commented 4 years ago

You can further investigate this issue by running the increment code in Cloud Code and debugging Parse Server. Look where the TypeError occurs, what the value of num is and go from there. Feel free to post your findings here.

lybaiyy123 commented 4 years ago

You can further investigate this issue by running the increment code in Cloud Code and debugging Parse Server. Look where the TypeError occurs, what the value of num is and go from there. Feel free to post your findings here.

ok,i will have a try, thanks your help

lybaiyy123 commented 4 years ago

Recurrence steps step 1: Delete the Class 'goods'

step2: Parse.Cloud.run('goods_update',{player:DB.player.id,num:10000000,name:'one_goods_name'})

the Cloud is:

Parse.Cloud.define('goods_update',req=>{`
    var {player,name,num=1}=req.params
    let g=new Parse.Query('goods')
    g.equalTo('player',player)
    g.equalTo('name',name)
    return g.first({useMasterKey:true}).then(data=>{
        console.log('===goods_update===')
        if (!data){
            if (num > 0){
                console.log(typeof num)
                let a = new Parse.Object('goods')
                a.set('player', player)
                a.set('name', name)
                a.set('type', GOODS[name].type)
                a.increment('num', num)
                a.set('level',GOODS[name].level)
                let acl = new Parse.ACL()
                acl.setReadAccess(req.user,true)
                acl.setWriteAccess(req.user,true)
                a.setACL(acl)
                return a.save(null, { useMasterKey: true })
            }else{
                throw new Parse.Error(1001,`${name} less than need`)
            }
        }else{
            if (num < 0 && data.get('num') < Math.abs(num)){
                throw new Parse.Error(1001,`${name} less than need`)
            }
            data.increment('num', num)
            return data.save(null,{useMasterKey:true})
        }
    })
})

step3 : Execute on client

var ccc=new Parse.Object('goods');
ccc.id='GPJ1Dl4psa' 
ccc.increment('num',-2)
ccc.save().then((data)=>{console.log(data.get('num'))})

error

lybaiyy123 commented 4 years ago

You can further investigate this issue by running the increment code in Cloud Code and debugging Parse Server. Look where the TypeError occurs, what the value of num is and go from there. Feel free to post your findings here. if not exec Parse.Cloud.run('goods_update',{player:DB.player.id,num:10000000,name:'one_goods_name'}) there is no error

mtrezza commented 4 years ago

@lybaiyy123 Since you are the only one who can reproduce the issue so far, I can only guide you in saying that you can look into the Parse Server code and set a breakpoint at where the type error happens, then inspect the variables and look at what the value of num is. That should give you a hint to investigate further. You can find instructions on how to set this up and run parse server locally here.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

mtrezza commented 4 years ago

I'm closing this issue due to inactivity and it was not possible to reproduce the issue. Feel free to re-open if you have any questions.