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

ExpressionAttributeNames/Values can include hyphens #321

Closed
metuuu opened this issue Nov 3, 2023 · 5 comments · Fixed by #322
Closed

ExpressionAttributeNames/Values can include hyphens #321

metuuu opened this issue Nov 3, 2023 · 5 comments · Fixed by #322

Comments

@metuuu
Copy link

metuuu commented Nov 3, 2023

Describe the bug
I have a map that include keys that contain hyphens. DynamoDB throws error when I try to update the map values.
\"ExpressionAttributeNames contains invalid key: Syntax error; key: \"#Cwxpw5TMn06X1-kscvMxS\"

It seems that electrodb uses the map keys as the ExpressionAttribute keys without removing special characters or hashing the keys.

For example updating

attribute: {
  type: "map",
  properties: {
    'example-key XXX _ 1 2 3 4': { type: "string" },
  }
}

Outputs

"UpdateExpression": "SET #map.#example-key XXX _ 1 2 3 4 = :example-key XXX _ 1 2 3 4_u0, ...

ElectroDB Version
2.10.5

ElectroDB Playground Link
Use the ElectroDB Playground

@tywalch
Copy link
Owner

tywalch commented Nov 3, 2023

Hi @metuuu 👋

First of all, how dare you.

Second of all, this is a good find.

In most cases the library strives limit the surface area of the validation and constraints it adds. This is typically because DynamoDB changes their own limits and constraints all the time, so it wouldn't be right for the library to try match/duplicate those.

I'll note this change see about improving the formatting of these expression attributes/names 👍

Does DynamoDB even allow for spaces in their field names? I've never tried.

@metuuu
Copy link
Author

metuuu commented Nov 4, 2023

My example was a bit over the top I agree 😄 I'm sure you don't have to worry about spaces.

Thank you!

@metuuu
Copy link
Author

metuuu commented Nov 4, 2023

Just to note that in my actual case I was storing images to an object and the image IDs were generated with nanoid which can include hyphens and underscore. UUIDs would also have the same issue.

images: {
  // { <image-id>: <s3-key> }
  type: CustomAttributeType<{ [imageId: string]: string }>>('any'),
}

@tywalch tywalch linked a pull request Nov 4, 2023 that will close this issue
@tywalch tywalch reopened this Nov 5, 2023
@tywalch
Copy link
Owner

tywalch commented Nov 5, 2023

I just published the fix with 2.10.6. You can use the same playground link you created to see the change in action

We can close this ticket when you've verified your use case 👍

@metuuu
Copy link
Author

metuuu commented Nov 9, 2023

All seems good! I agree with your solution, that if someone wants to shoot themselves in the leg by trying to store two items like test-item & testitem to same map its completely their own fault.

Thank you 🙏🏻

@metuuu metuuu closed this as completed Nov 9, 2023
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 a pull request may close this issue.

2 participants