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] Inconsistent items are generated when an item is created and when an item is fetched from the database

See original GitHub issue

Summary:

When creating a new item using a model the field aliases are not accessible. When fetching an item the main field itself is not accessible only its alias is.

Disclaimer: I have only tried this in dynamodb local and with dynamoose v3 so can’t say if this is the expected behavior or is bug. It was suggested in Slack that ticket is created https://dynamoose.slack.com/archives/CG4B7RL8N/p1661138601979229

Code sample:

    const User = dynamoose.model("User", {"pk": {"type": String, "alias": "email"}});
    new dynamoose.Table("User", [User]);

    const user1 = await User.create({ "email": "joe@doe.com" })
    const user2 = await User.create({ "pk": "jane@doe.com" })

    console.log(user1, user1.email) // User { pk: 'joe@doe.com' } undefined
    console.log(user2, user2.email) // User { pk: 'jane@doe.com' } undefined

    const user3 = await User.get('jane@doe.com')
    console.log(user3, user3.pk) // User { email: 'jane@doe.com' } undefined

Current output and behavior (including stack trace):

The current output is inlined in the code example above

Expected output and behavior:

The expected behavior is for Model.create() and Model.get() generate consistent items. Both the DDB field and the alias should be accessible in the generated items.

Environment:

Operating System: Ubuntu Operating System Version: 20.04.2 LTS Node.js version (node -v): v14.19.0 NPM version: (npm -v): 8.6.0 Dynamoose version: 3.0.0

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:open
  • Created a year ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
hpinheiro-godaddycommented, Sep 4, 2022

try to include mapAttributes: true

1reaction
ptejadacommented, Sep 4, 2022

Beautiful! Thank you @hpinheiro-godaddy! Using mapAttributes: true works 👍.

I removed some of the other settings that I don’t know what they do ended up with this:

    console.log(await item.conformToSchema({     
      mapAttributes: true,      
      modifiers: ["get"],
      type: "fromDynamo"
    }))

    //  test { id: '4yt0iHubQJoMJiy', range: '6P4u3rVVTlQBiFr' }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
Database Integrity Suggestion Warning - OutSystems 11 ...
Message: Inconsistent database table and entity definitions: 'Binary Data' column <!--table-->.<column> exists in database, but there is no ...
Read more >
SQLSTATE values and common error codes - IBM
Each five-character value is a return code that indicates the outcome of the most recently executed SQL statement. SQLSTATE values are designed so...
Read more >
How to Fix Inconsistent Data type Error While Populating ...
I have created an Object type and nested table based on this object type ... The current version of Oracle is Oracle Database...
Read more >
Common Hibernate Exceptions - Baeldung
SQLGrammarException indicates that the SQL sent to the database was invalid. It could be due to a syntax error or an invalid object...
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