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 type error message shows as object #1077

Closed
6 tasks done
fishcharlie opened this issue Dec 12, 2020 · 4 comments · Fixed by #1148
Closed
6 tasks done

[BUG] null type error message shows as object #1077

fishcharlie opened this issue Dec 12, 2020 · 4 comments · Fixed by #1148
Assignees
Labels

Comments

@fishcharlie
Copy link
Member

fishcharlie commented Dec 12, 2020

Summary:

If your document has a null attribute value, and your schema doesn't allow for null type, you get an error saying:

TypeMismatch: Expected name to be of type string, instead found type object.

Ideally this would be:

TypeMismatch: Expected name to be of type string, instead found type null.

Current output and behavior (including stack trace):

TypeMismatch: Expected name to be of type string, instead found type object.

Expected output and behavior:

TypeMismatch: Expected name to be of type string, instead found type null.

Environment:

Operating System: macOS
Operating System Version: 11.1 (20C69)
Node.js version (node -v): v14.0.0
NPM version: (npm -v): 6.14.4
Dynamoose version: v2.5.0

Other information (if applicable):

https://dynamoose.slack.com/archives/CG4B7RL8N/p1607747047084500?thread_ts=1607743869.070600&cid=CG4B7RL8N

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
@isupremedyou
Copy link

This also appears to implicate the use of the saveUnknown attribute, if the properties allowed to saveUnknown contain a null value.

In my example and use case I am interfacing with a third party and caching data from them. I am attempting to use one of my columns to store an object that has dynamic keys. So I have a schema like this:

const peopleCacheSchema = new dynamoose.Schema(
    {
        accountId: { type: Number, hashKey: true },
        personId: { type: String, rangeKey: true },
        firstName: String,
        lastName: String,
        phone: String,
        email: String,
        customFields: {
            type: Object,
        }
    },
    {
        saveUnknown: ["customFields.**"],
        timestamps: {
            createdAt: ["createAt"],
            updatedAt: ["updateAt"],
        },
    },
);

If the third party has a key/value pair in the customFields object, such as { orderId: null }, and I save the item with the above schema and via dynamoose, the item is capable of saving to dynamo just fine, but the error is thrown:

ERROR TypeMismatch: Expected personId to be of type string, instead found type object. at checkTypeFunction

@fishcharlie
Copy link
Member Author

@isupremedyou What version of Dynamoose are you using?

@isupremedyou
Copy link

@fishcharlie
2.3.0. I can upgrade to 2.5.0 this morning and see if it is resolved.

@fishcharlie
Copy link
Member Author

@isupremedyou

the item is capable of saving to dynamo just fine

So the null property type only works in version 2.5.0. You can read the release notes here.

This issue still exists on 2.5.0. But try your thing on 2.5.0, and let me know how it goes. I think it should work, but I don't understand all the details of your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants