[BUG] Inconsistent items are generated when an item is created and when an item is fetched from the database
See original GitHub issueSummary:
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:
- Created a year ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
try to include
mapAttributes: true
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: