Dynamoid / dynamoid

Ruby ORM for Amazon's DynamoDB.
MIT License
582 stars 195 forks source link

Error querying fields starting with special characters #808

Closed thelibrarian closed 1 month ago

thelibrarian commented 1 month ago

Hi, as of Dyanmoid 3.10.0, with the merge of #655, Dynamoid no longer works with fields that start with "special" characters such as underscores in where conditions. It may also be failing with fields that contain special characters such as full stops and dashes anywhere in the field name. These names should be accounted for with the use of expression attribute names.

These queries have long worked with Dynamoid, and still work with 3.9.0, but have stopped working as of 3.10.0.

Error message from aws-sdk-dynamodb:

Invalid KeyConditionExpression: Syntax error; token: "_", near: "AND _sortKey"
andrykonchin commented 1 month ago

Thank you for reporting the issue. Will work on it.

The simplest options seem to be either:

thelibrarian commented 1 month ago

I agree, and both approaches have their plusses and minuses. Using expression attribute names for all attributes is probably the safest, but may make queries run a little slower. Checking for reserved names and special characters and using expression attribute names for only those cases may make the query slightly more efficient but adds the overhead of maintaining that list and the possibility of missing some cases.