question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Type Mismatch error message on hashKey when unrelated field is null

See original GitHub issue

Summary:

Thanks for your great work with dynamoose!

I’ve been porting over a codebase from dynamoose 1 -> 2, and I noticed a weird issue.

Writing a document with a null field and a schema with saveUnknown: true, then querying it causes a "Type Mismatch’ error that complains about the hashKey: UnhandledPromiseRejectionWarning: TypeMismatch: Expected hashKey to be of type string, instead found type object.

Removing the null field or removing saveUnknown: true causes the query to complete normally.

There’s two aspects to this as far as I can tell:

  1. It’s unclear whether having a field that is null with saveUnknown is a problem
  2. The type mismatch error blames a seemingly unrelated hashKey.

I’ve created a minimal-ish reproduction of the problem, using dynamodb local. Clone the repo, npm install then run npm test to see the problem.

Code sample:

https://github.com/willheslam/dynamoose-type-mismatch/

Schema

const schema = new dynamoose.Schema(
  {
    hashKey: {
      type: String,
      hashKey: true,
      required: true,
    },
  },
  { saveUnknown: true }
)

Model

const MyModel = dynamoose.model("mytable", schema, modelOptions)

General

    await MyModel.batchPut([
      {
        hashKey: "foo",
        bar: null, // comment this out and the type mismatch goes away
      },
    ])
    const records = await MyModel.query({ hashKey: { eq: "foo" } }).exec()

Current output and behavior (including stack trace):

(node:25257) UnhandledPromiseRejectionWarning: TypeMismatch: Expected hashKey to be of type string, instead found type object.
    at checkTypeFunction (/Users/will.heslam/recreate-dynamoose-bug/node_modules/dynamoose/lib/Document.ts:263:11)
    at Array.map (<anonymous>)
    at Function.<anonymous> (/Users/will.heslam/recreate-dynamoose-bug/node_modules/dynamoose/lib/Document.ts:282:111)
    at Generator.next (<anonymous>)
    at /Users/will.heslam/recreate-dynamoose-bug/node_modules/dynamoose/dist/Document.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/will.heslam/recreate-dynamoose-bug/node_modules/dynamoose/dist/Document.js:4:12)
    at Function.Document.objectFromSchema (/Users/will.heslam/recreate-dynamoose-bug/node_modules/dynamoose/dist/Document.js:192:12)
    at Document.<anonymous> (/Users/will.heslam/recreate-dynamoose-bug/node_modules/dynamoose/lib/Document.ts:421:40)
    at Generator.next (<anonymous>)

Expected output and behavior:

records [
  Document { hashKey: 'foo', foo: null },
  lastKey: undefined,
  count: 1,
  queriedCount: undefined,
  timesQueried: 1
]

Environment:

Operating System: Operating System Version: Node.js version (node -v): v12.14.1 NPM version: (npm -v): 6.13.4 Dynamoose version: 2.1.2

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
fishcharliecommented, May 7, 2020

@willheslam This is actually intentional. It is in preparation for supporting the DynamoDB null type in the future.

You can find this in the breaking change log:

Trying to save a Document with a property set to null will now throw an error. If you would like to remove the property set it to dynamoose.UNDEFINED to set it to undefined without taking into account the default setting, or undefined to set it to undefined while taking into account the default setting.

It is kinda a pain I know. But I felt like this was a worthwhile tradeoff to be able to support the native DynamoDB null type in the future.

0reactions
softmarshmallowcommented, Dec 7, 2020

https://github.com/dynamoose/dynamoose/issues/815

  id: 'Ej4ZE0vrGRohG6k4_a_Ed',
  projectId: 'temp',
  fileId: '',
  nodeId: '6671:952',
  sdkVersion: 'v2020.0',
  designPlatform: 'com.figma.Desktop',
  cachedPreview: '',
  sceneType: 'SCREEN',
  route: Symbol(dynamoose.undefined),
  name: 'Frame 1333',
  description: Symbol(dynamoose.undefined),
  tags: [],
  alias: Symbol(dynamoose.undefined),
  variant: Symbol(dynamoose.undefined),
  layers: [
    {
      nodeId: 'I6671:933;2074:140553;2074:140542',
      index: 3,
      name: 'profile/customer/40',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'VANILLA',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 44,
      height: 44,
      x: 48,
      y: 70
    },
    {
      nodeId: 'I6671:933;2074:140553;2074:140542',
      index: 1003,
      name: '(bg-converted) profile/customer/40',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'RECT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 44,
      height: 44,
      x: 48,
      y: 70
    },
    {
      nodeId: 'I6671:933;2074:140553;2074:140543',
      index: 4,
      name: 'customer/{name}',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'TEXT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 227,
      height: 21,
      x: 100,
      y: 81.5
    },
    {
      nodeId: 'I6671:933;2074:140553',
      index: 1002,
      name: '(bg-converted) segments/customer/ (mini)',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'RECT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 279,
      height: 44,
      x: 48,
      y: 70
    },
    {
      nodeId: 'I6671:933;1902:11729;1875:118413',
      index: 4,
      name: 'Frame 325',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'VANILLA',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 279,
      height: 8,
      x: 48,
      y: 130
    },
    {
      nodeId: 'I6671:933;1902:11729;1875:118413',
      index: 1004,
      name: '(bg-converted) Frame 325',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'RECT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 279,
      height: 8,
      x: 48,
      y: 130
    },
    {
      nodeId: 'I6671:933;1902:11729;1875:118416',
      index: 5,
      name: 'segments/customer/status/customer-steady',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'TEXT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 92,
      height: 16,
      x: 48,
      y: 144
    },
    {
      nodeId: 'I6671:933;1902:11729',
      index: 1003,
      name: '(bg-converted) segments/customer/status/customer-steady',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'RECT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 279,
      height: 30,
      x: 48,
      y: 130
    },
    {
      nodeId: 'I6671:933;1314:480',
      index: 4,
      name: 'Date of Issue : 2020/05/10',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'TEXT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 143,
      height: 14,
      x: 48,
      y: 176
    },
    {
      nodeId: '6671:933',
      index: 1001,
      name: '(bg-converted) rows/kit-customer',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'RECT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 327,
      height: 168,
      x: 24,
      y: 46
    },
    {
      nodeId: '6671:952',
      index: null,
      name: '(bg-converted) Frame 1333',
      sdkVersion: 'v2020.0',
      data: [Object],
      type: 'RECT',
      layers: Symbol(dynamoose.undefined),
      componentId: Symbol(dynamoose.undefined),
      width: 375,
      height: 298,
      x: 0,
      y: 0
    }
  ],
  width: 375,
  height: 298
}
[Nest] 51547   - 12/07/2020, 11:30:08 AM   [ExceptionsHandler] Cannot convert undefined or null to object +67ms
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at Schema.getTypePaths (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Schema.ts:377:17)
    at /Users//Documents/GitHub/services/node_modules/dynamoose/lib/Schema.ts:446:34
    at Array.reduce (<anonymous>)
    at Schema.getTypePaths (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Schema.ts:377:33)
    at /Users//Documents/GitHub/services/node_modules/dynamoose/lib/Schema.ts:446:34
    at Array.reduce (<anonymous>)
    at Schema.getTypePaths (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Schema.ts:377:33)
    at /Users//Documents/GitHub/services/node_modules/dynamoose/lib/Schema.ts:446:34
    at Array.reduce (<anonymous>)
    at Schema.getTypePaths (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Schema.ts:377:33)
    at /Users//Documents/GitHub/services/node_modules/dynamoose/lib/Model/index.ts:417:81
    at Array.map (<anonymous>)
    at Model.schemaForObject (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Model/index.ts:417:58)
    at Function.Document.prepareForObjectFromSchema (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Document.ts:200:38)
    at Document.toDynamo (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Document.ts:491:17)
    at Document.save (/Users//Documents/GitHub/services/node_modules/dynamoose/lib/Document.ts:142:30)
    at ScenesService.<anonymous> (/Users//Documents/GitHub/services/scene-store-service/src/scenes/scenes.service.ts:51:35)

Replaced all null / undefined to dynamoose.UNDEFINED, still getting the same error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BigQuery count(*) throws type mismatch error - Stack Overflow
This is a bug in BigQuery type coercion. While several workarounds are possible - we have fixed the underlying issue inside BigQuery, ...
Read more >
2008-January.txt - Python mailing list
Fields ("BUG") Attribute Customization not in cache Getting property Id 0x1a from OLE ... None, 1) How the heck do you get a...
Read more >
I get a message about data type mismatch - Microsoft Support
This error indicates that Access cannot match an input value to the data type it expects for the value. For example, if you...
Read more >
PHP 7 ChangeLog
Fixed bug #81037 (PDO discards error message text from prepared statement). ... Fixed bug #79193 (Incorrect type inference for self::$field =& $field).
Read more >
Known issues - PaperCut
Hitting a problem with your PaperCut implementation? You might not be alone! ... Print Deploy Client may show "Can't reach this page" error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found