Why is putting an object in local dynamodb table changing some field of the said object?

186 Views Asked by At

This is an extremely weird one. I'm using datamapper for dynamo and dynamolocal in typescript to test my stuff. For some reason it overwrites one object field and I can't figure out why.

I'm seeding the table like so:

private async seedTable() {
        // FIRST PART
        for (const obj of [...objects]) {
            const toSave = new MyObject().fromPartial({
                ...obj
            });
            console.log(`myBool: ${toSave.myBool}`);
            await this.ddbMapper.put(toSave);
        }

        // SECOND PART
        await this.ddbMapper.put(
            new MyObject().fromPartial({
                ...objects[0],
                objId: "test",
                myBool: false
            })
        );
    }

In this previous snippet, the objects from the for loop will print: "myBool: false"

however in the table they will be true (what?)

the second part where I hardcode the object, it's getting saved with myBool: false as I would expect

If I overwrite the value it works but if I keep the original object it switches to true for no apparent reason.

this is the fromPartial implementation

public fromPartial(data: Partial<MyObject>): MyObject {
        Object.assign(this, data);
        return this;
    }

is this a bug from dynamodb / dynamodb-local / my implementation / javascript / typescript ? does anybody have a clue into what could be the source of the issue ?

Edit: ddbmapper is the DataMapper class from dynamodb-data-mapper

1

There are 1 best solutions below

0
Shraneid On

Ok found the issue, actually the value was "false" instead of false which the mapper seems to force at runtime so the string evaluates to true. Kind of a weird behaviour when you know that passing an object with correct properties but no type does not work with datamapper : the github issue I'm talking about issue