99x / 99x/serverless-dynamodb-local

Null object properties not supported in seed

Open
#170 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
621
Forks
232
PR merge metrics
No merged PRs in 30d

Description

**Actual Behaviour**

Seed does not support objects with a top-level property that has a null value.
`{ a: '1', b: null }` does not work
`{ a: '1', b: '2' }` works
_Note_ nested null values work (`{ a: '1', b: { c: '2', d: null } }` works)

**Expected Behaviour**

Seed objects should allow for the "null" value in a top-level property.

**Steps to reproduce it**

1. Create a seed file with a null property (i.e. `{ a: '1', b: null }`)
2. Run start with seed
3. Crash with `cannot read property 'type' of null` error

**LogCat for the issue**

```
$ sls dynamodb start --seed=dev
Dynamodb Local Started, Visit: http://localhost:8000/shell
Serverless: DynamoDB - created table test-db

Type Error ---------------------------------------------

Cannot read property 'type' of null

For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

Stack Trace --------------------------------------------

TypeError: Cannot read property 'type' of null
at ____\node_modules\serverless-dynamodb-local\src\seeder.js:100:14
at ____\node_modules\lodash\lodash.js:4925:15
at baseForOwn (____\node_modules\lodash\lodash.js:3010:24)
at ____\node_modules\lodash\lodash.js:4894:18
at Function.forEach (____\node_modules\lodash\lodash.js:9342:14)
at unmarshalBuffer (____\node_modules\serverless-dynamodb-local\src\seeder.js:98:5)
at arrayEach (____\node_modules\lodash\lodash.js:516:11)
at Function.forEach (____\node_modules\lodash\lodash.js:9342:14)
at getSeedsAtLocation (____\node_modules\serverless-dynamodb-local\src\seeder.js:120:14)
at fileExists.then (____\node_modules\serverless-dynamodb-local\src\seeder.js:140:14)
From previous event:
at PluginManager.invoke (%APPDATA%\npm\node_modules\serverless\lib\classes\PluginManager.js:368:22)
at PluginManager.run (%APPDATA%\npm\node_modules\serverless\lib\classes\PluginManager.js:399:17)
at variables.populateService.then (%APPDATA%\npm\node_modules\serverless\lib\Serverless.js:102:33)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
at Serverless.run (%APPDATA%\npm\node_modules\serverless\lib\Serverless.js:89:74)
at serverless.init.then (%APPDATA%\npm\node_modules\serverless\bin\serverless:42:50)

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless

Your Environment Information -----------------------------
OS: win32
Node Version: 6.11.3
Serverless Version: 1.25.0
```
I removed local filesystem prefixes, `____` is the project directory

**Screenshots of the issue**

N/A

**Would you like to work on the issue?**

In src/seeder.js you should just be able to add a null check to the unmarshalBuffer function on line 99:
`if (value !== null && value.type==="Buffer")`
instead of
`if (value.type==="Buffer")`
I won't have time to work on it, but I know this works with the cases I have.

Contributor guide

Open the contributing guide

Research direction

Start in src/seeder.js at unmarshalBuffer, around the line shown in the stack trace, and inspect how top-level seed values are handled. Re-run `sls dynamodb start --seed=dev` with `{ a: '1', b: null }`; done means the seed loads without the null-property crash while nested null values continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
database
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.