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

[BUG] NULL values are ignored or throw an error with saveUnknown #1679

Open
6 tasks done
toronto-devops opened this issue May 14, 2024 · 0 comments
Open
6 tasks done

Comments

@toronto-devops
Copy link

Summary:

null values inside Objects with saveUnknown=true are either omitted or throw an error.

Example 1: Omitted Value

const Test = dynamoose.model(
  'Test',
  new dynamoose.Schema(
    {
      id: {
        type: String,
        index: true,
      },
      data: Object,
    },
    { saveUnknown: true },
  ),
);
const test = new Test({
  id: '123',
  data: { key: null },
});
const val = await test.toDynamo();
console.log(JSON.stringify(val, null, 2));

Current output and behavior (including stack trace):

{
  "id": {
    "S": "123"
  },
  "data": {
    "M": {}
  }
}

Expected output and behavior:

{
  "id": {
    "S": "123"
  },
  "data": {
    "M": {
      "key": {
        "NULL": true
      }
    }
  }
}

Example 2: Throws Error

  • Note that the only thing that's changed is the model property order.
const Test = dynamoose.model(
  'Test',
  new dynamoose.Schema(
    {
      id: {
        type: String,
        index: true,
      },
      data: Object,
    },
    { saveUnknown: true },
  ),
);
const test = new Test({
  data: { key: null },
  id: '123',
});
const val = await test.toDynamo();
console.log(JSON.stringify(val, null, 2));

Current output and behavior (including stack trace):

/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/node_modules/dynamoose/dist/Item.js:63
        const keys = Object.keys(object);
                            ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Item.isDynamoObject (/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/node_modules/dynamoose/dist/Item.js:63:29)
    at isValid (/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/node_modules/dynamoose/dist/Item.js:58:238)
    at /home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/node_modules/dynamoose/dist/Item.js:69:74
    at Array.every (<anonymous>)
    at Item.isDynamoObject (/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/node_modules/dynamoose/dist/Item.js:69:57)
    at new Item (/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/node_modules/dynamoose/dist/Item.js:25:33)
    at new Test (/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/node_modules/dynamoose/dist/Model/index.js:211:17)
    at main (/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/lib/migrate.js:35:18)
    at Object.<anonymous> (/home/devops.toronto/src/github.com/compassdigital/cdl/api/platform2/announcement/lib/migrate.js:42:1)

Expected output and behavior:

{
  "id": {
    "S": "123"
  },
  "data": {
    "M": {
      "key": {
        "NULL": true
      }
    }
  }
}

Environment:

Operating System: Ubuntu
Operating System Version: 20.04
Node.js version (node -v): v20.11.0
NPM version: (npm -v): 10.2.4
Dynamoose version: 4.0.1

Other information (if applicable):

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant