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

fix formatting unique expression attribute names #461

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

anatolzak
Copy link

closes #460

Previous behavior:

When updating an item with a map attribute, if you attempt to set multiple keys that are identical after removing non-word characters (\w), Electro will generate the same expression attribute name for both keys. This occurs even though the original keys are different, leading to conflicts in the update operation.

This PR introduces a new change that ensures that each key will generate a unique expression attribute name.

Previously the following operation

tasks.patch({ id: '1' }).data((attrs, ops) => {
  ops.set(attrs.map['hello world'], 1)
  ops.set(attrs.map['hello    world'], 1)
}).go()

would generate only 1 expression attribute name #helloworld. this also throws an error in dynamo because you are not allowed to update the same field multiple times in the same operation.

The new PR would create 2 expression attribute names: #helloworld and #helloworld_2.

I added tests for this as well.

Copy link

netlify bot commented Jan 6, 2025

Deploy Preview for electrodb-dev canceled.

Name Link
🔨 Latest commit de1fc11
🔍 Latest deploy log https://app.netlify.com/sites/electrodb-dev/deploys/677ce2e35db80800086b90ac

@anatolzak anatolzak changed the title fix formatting expression attribute names fix formatting unique expression attribute names Jan 6, 2025
@tywalch
Copy link
Owner

tywalch commented Jan 9, 2025

Thanks @anatolzak! I'll need some time to check this out, but at first glance, I appreciate the addition of tests!

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

Successfully merging this pull request may close these issues.

Duplicate Expression Attribute Names When Updating Map Attribute Keys
2 participants