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

client.query returns undefined #31

Open
daianaszwimer opened this issue Jan 7, 2021 · 8 comments
Open

client.query returns undefined #31

daianaszwimer opened this issue Jan 7, 2021 · 8 comments
Labels
dependencies Pull requests that update a dependency file

Comments

@daianaszwimer
Copy link

I'm executing this function on my test:

const params = {
    TableName: TABLE_NAME,
    IndexName: TREE_INDEX,
    KeyConditionExpression: "parent = :parent",
    FilterExpression : "#l = :level",
    ExpressionAttributeNames: {
        "#l": "level"
    },
    ExpressionAttributeValues: {
        ":level": this.level,
        ":parent": parent
    }
};
const result = await this.db.query(params);

And result is undefined when it should return an array of items and when it should return an empty array

I have other queries on my code that have an index that work ok, but this one has an index and a filter expression, and for some reason, it's not working as expected

Attached you can see that when I want to access result.Items I get an error because result is undefined

Screen Shot 2021-01-07 at 17 32 14

PS: this.db is an instance of DocumentClient

@freshollie
Copy link
Owner

Which version of the aws-sdk are you using? I'm pretty sure you need a .promise() on the end of your query?

@daianaszwimer
Copy link
Author

@freshollie i'm using the version ^2.541.0. And yes, I'm using the promise() at the end, I forgot to clarify that. The this.db references a file that exports {query: (params) => client.query(params).promise()} (among other functions as well), so the db call is ok

@freshollie
Copy link
Owner

Very interesting. From my point of view, jest-dynalite does nothing to the actual aws-sdk module, and thus, the fact the function is returning undefined is something going on with the SDK, as Result type should always be returned from a query.

Are you able to produce a reproduction? Does this code work when you connect to a dynamodb-local instance?

@daianaszwimer
Copy link
Author

@freshollie
I debugged and the problem seems to be related to line 54 on dynalite/actions/query.js

if (!data.KeyConditions[attr]) {
  if (isHash || Object.keys(data.KeyConditions).length > 1) {
    return db.validationError('Query condition missed key schema element: ' + attr)
  }
  return
}

!data.KeyConditions[attr] returns true but isHash || Object.keys(data.KeyConditions).length > 1 is false so it returns undefined

@freshollie
Copy link
Owner

Interesting, do you know what the code should do instead of returning undefined? Might it be worth putting in an upstream PR?

@daianaszwimer
Copy link
Author

@freshollie idk if this answers your question but the code should return what the query needs which is a result object with the Items key that has an array with the results from the DB

@freshollie freshollie added the dependencies Pull requests that update a dependency file label Jan 13, 2021
@freshollie
Copy link
Owner

@daianaszwimer have you tried executing this expression against a real dynamodb instance? I have a feeling your query is wrong but the return is just missing the correct error information.

@daianaszwimer
Copy link
Author

yes, I have :) The query works fine @freshollie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants