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

[Datastore] saving error: Illegal value for [object Object] of type double: string (not a number) #1421

Closed
gromtech opened this issue Jul 12, 2016 · 4 comments
Assignees
Labels
api: datastore Issues related to the Datastore API.

Comments

@gromtech
Copy link

gromtech commented Jul 12, 2016

I updated the gloud up to 0.36.0 version (preveous 0.33.0) and currently I cannot save the data to the datastore using by gcloud.datastore.save(entities, callback). When I tried to save the entities

[
    {
        "key": {
            "name": "120",
            "kind": "CD_Campaign",
            "path": [
                "CD_Campaign",
                "120"
            ]
        },
        "data": {
            "persons": 20,
            "attempted": 0,
            "contacted": 0,
            "bounds": {
                "min": {
                    "lng": -122.50355,
                    "lat": 37.70851
                },
                "max": {
                    "lng": -122.43805,
                    "lat": 37.7907
                }
            },
            "disp": {
                "NH": 0,
                "LD": 0,
                "VC": 0,
                "LB": 0,
                "D": 0,
                "NC": 0,
                "IN": 0,
                "DC": 0,
                "RF": 0,
                "MV": 0,
                "WN": 0,
                "AV": 0,
                "V": 0,
                "B": 0,
                "LM": 0,
                "CB": 0
            },
            "areaIds": [
                "0500000US06075"
            ]
        }
    }
]

I got the error:

> Error: Illegal value for [object Object] of type double: string (not a number)
>     at Error (native)
>     at null.<anonymous> (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:1769:23)
>     at ProtoBuf.Reflect.ElementPrototype.verifyValue (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:1825:25)
>     at ProtoBuf.Reflect.FieldPrototype.verifyValue (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:3436:33)
>     at MessagePrototype.set (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:2443:59)
>     at MessagePrototype.set (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:2434:38)
>     at Message (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:2363:34)
>     at ProtoBuf.Reflect.ElementPrototype.verifyValue (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:1877:28)
>     at new ProtoBuf.Map.Map (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:4894:46)
>     at ProtoBuf.Reflect.FieldPrototype.verifyValue (C:\Data\Projects\dashboard\node_modules\protobufjs\dist\ProtoBuf.js:3427:28)

Maybe problem in ProtoBuf.js or in another methods which are sending float value as string into ProtoBuf.js. As a hot fix I changed the code in ProtoBuf.js (line 1825):

                // Float
                case ProtoBuf.TYPES["float"]:
                case ProtoBuf.TYPES["double"]:
/*                    if (typeof value !== 'number')
                       fail(typeof value, "not a number");
                    return value;*/

                    // hot fix
                    if (typeof value !== 'number') {
                        if (typeof value === 'string') {
                            var asFloat=parseFloat(value);
                            if (isNaN(asFloat)) {
                                fail(typeof value, "not a number");
                            } else {
                                return asFloat;
                            }
                        } else {
                            fail(typeof value, "not a number");
                        }
                    }
                    return value;
@stephenplusplus stephenplusplus added the api: datastore Issues related to the Datastore API. label Jul 12, 2016
@stephenplusplus
Copy link
Contributor

I wasn't able to reproduce this error. Would you create a bare-minimum repo that reproduces this bug consistently?

@gromtech
Copy link
Author

I reproduced this bug when I used the "stephenplusplus/gcloud-node#spp--1412" version. The bare-minimum repo is here:

$ git clone https://bitbucket.org/gromtech/gcloud-node-1421.git

@stephenplusplus
Copy link
Contributor

Okay, that explains it. I'll try to find a fix.

@stephenplusplus
Copy link
Contributor

Going to link to this issue in the PR, since this isn't actually broken on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API.
Projects
None yet
Development

No branches or pull requests

2 participants