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] TypeMismatch error when attribute is called 'model'

See original GitHub issue

Summary:

When trying to create an item using a schema, dynamoose triggers a TypeMismatch error when using an attribute called ‘model’. It works fine with any other attribute name.

Code sample:

Schema

const dynamoose = require('dynamoose');

const testSchema = new dynamoose.Schema({
    _id: {
        type: String,
        hashKey: true,
    },
    model: {
        type: Array,
        schema: [
            {
                type: Object,
                schema: {
                    _id: String,
                    text: String,
                },
            },
        ],
    }
}, { saveUnkown: true, create:true }
);

module.exports = dynamoose.model('ModelTest', testSchema);

Model

// Code here

General

index.js

const dynamoose = require('dynamoose');
const Model = require('./model')
const { sdk } = dynamoose.aws;

sdk.config.update({
    region: 'fake',
});

dynamoose.aws.ddb.local('http://localhost:8001');


async function runTest() {

    try {
        const newModel = await Model.create(
            {   
                _id: '123',  
                model: [
                    { _id: '12345678', text: 'someText' }
                ]
            }
        );

        console.log(newModel);
        
    } catch(err){
        console.log(err)
    }

}


runTest();

Current output and behavior (including stack trace):

TypeMismatch: Expected model to be of type array, instead found type object. at checkTypeFunction (…\node_modules\dynamoose\lib\Document.ts:302:11) at Array.map (<anonymous>) at Function.<anonymous> (…\node_modules\dynamoose\lib\Document.ts:323:111) at Generator.next (<anonymous>) at fulfilled (…\node_modules\dynamoose\dist\Document.js:5:58)

Expected output and behavior:

Output behavior when using the attribute as ‘model1’

Document {
  _id: '123',
  model1: [ { _id: '12345678', text: 'someText' } ]
}

Environment:

Operating System: Windows Operating System Version: Windows 10 Enterprise Node.js version (v12.18.2): NPM version: (6.14.5): Dynamoose version: 2.3.0

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
  • Reactions:5
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
fishcharliecommented, Nov 6, 2020

@gmaragao I don’t see this being addressed anytime soon. This will require a strong line by line assessment of the project to determine what we need to do here. I don’t think this will happen anytime soon.

If you would like to attempt to put up a PR for this, that’d be awesome.

0reactions
nimit2801commented, Sep 12, 2022

@nimit2801 I am very sorry to say, but honestly I haven’t tested the new functionally yet.

May I ask why? Does the problem also occur in the new version of the library?

I’m actually using $ADD from the Docs to add String Set ref link from docs And while I’m trying to pass Array or String, it throw a TypeMismatch: Expected likedMe to be of type string set, instead found type object. Reference to discussion opened #1512

Read more comments on GitHub >

github_iconTop Results From Across the Web

VBA Type Mismatch Error - The Ultimate Guide
A VBA Type Mismatch Error occurs when you try to assign a value between two different variable types. The error appears as “run-time...
Read more >
Type mismatch (Error 13) | Microsoft Learn
Cause: An object was passed to a procedure that is expecting a single property or value. Solution: Pass the appropriate single property or...
Read more >
Type mismatch, when passing arugment to Model Class
I have fixed the type-mismatch error by making model class variable as nullable. But I couldn't understand the error shown by the compiler....
Read more >
VBA Type Mismatch Error (Error 13) - Excel Champs
Type Mismatch (Error 13) occurs when you try to specify a value to a variable that doesn't match with its data type. In...
Read more >
VBA - Type Mismatch (Run-time Error 13) - Automate Excel
This will prevent the user inserting rows, and entering unexpected data. Mismatch Error Caused by Calling a Function or Sub Routine Using ...
Read more >

github_iconTop Related Medium Post

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