Skip to content

[BUG] Raw condition does not with with query. #1618

Open
@bushev

Description

@bushev

Summary:

Code sample:

const condition = new dynamoose.Condition()
  .where('userId')
  .eq(options.userId)
  .parenthesis(
    new dynamoose.Condition({
      FilterExpression: 'size (#templates) <> :size',
      ExpressionAttributeValues: {
        ':size': 0
      },
      ExpressionAttributeNames: {
        '#templates': 'templates'
      }
    })
  );

const query = myModel.query(condition);
const result = await query.all().exec();

Model

export const schema = new Schema(
  {
    userId: {
      type: String,
      hashKey: true,
      validate: new RegExp(uuidV4RegExStr, 'i'),
      required: true
    },
   createdAt: {
      type: String,
      rangeKey: true,
      required: true
    },
   templates: {
      type: Array,
      schema: [
        {
          type: Object,
          schema: {
            pId: {
              type: String,
              required: true
            },
            sec: {
              type: String,
              required: true
            }
          }
        }
      ],
      required: true
    },
  {
    timestamps: false,
  }
)

Current output and behavior (including stack trace):

TypeError: Cannot read properties of undefined (reading '0')
    at /Users/u/a/b/node_modules/dynamoose/dist/Condition.js:188:39
    at Array.reduce (<anonymous>)
    at Object.comparisonChart (/Users/u/a/b/node_modules/dynamoose/dist/Condition.js:185:108)
    at Query.ItemRetriever.getRequest (/Users/u/a/b/node_modules/dynamoose/dist/ItemRetriever.js:135:147)

Expected output and behavior:

Normal execution

Environment:

Operating System: MacOS
Operating System Version: 13.4.1 (22F82)
Node.js version (node -v): v16.13.2
NPM version: (npm -v): 8.1.2
Dynamoose version: 3.2.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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions