question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamodb client query behaves differently depending on whether it is a new client or it comes from the resource

See original GitHub issue

I have a parameters variable

params = {
        "TableName": "name_of_table",
        "KeyConditionExpression": "user_id = :user_id",
        "ExpressionAttributeValues": {
            ":user_id": { "S": "username" }
        },
    }

I also created a client

client = boto3.client("dynamodb") and ran

client.query(**params) which returns the correct data from our table. But when we create a resource

resource = boto3.resource("dynamodb")

and run

resource.meta.client.query(**params)

I get the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the Query operation: One or more parameter values were invalid: Condition parameter type does not match schema type

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
jg75commented, Sep 11, 2019

It looks like client.query requires the attribute values to be in the encoded format, i.e. ":user_id": { "S": "username" } but the resource.meta.client.query requires it to be uncoded, i.e. ":user_id": "username" EDIT: The documentation leads me to believe that it should be encoded in both cases

3reactions
JeremieRodoncommented, Jan 10, 2021

I think you missed his point. I believe it is fair to expect that boto3.client('dynamodb') and boto3.resource('dynamodb').meta.client should behave the same way and his example demonstrate that it is not the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class: Aws::DynamoDB::Client — AWS SDK for Ruby V2
Creates a new item, or replaces an old item with a new item. #query(options = {}) ⇒ Types::QueryOutput. The Query operation finds items...
Read more >
DynamoDB — Boto3 Docs 1.26.34 documentation - AWS
With DynamoDB, you can create database tables that can store and retrieve any amount of data, and serve any level of request traffic....
Read more >
6 Common DynamoDB Issues - Dashbird
1. Query Condition Missed Key Schema Element · 2. Resource Not Found Exception · 3. Cannot do Operations on a Non-Existent Table ·...
Read more >
Ten Examples of Getting Data from DynamoDB with Python ...
We'll use both a DynamoDB client and a DynamoDB table resource in ... or you can quickly create your new DynamoDB table with...
Read more >
Why Your DynamoDB Scan or Query Is Not Returning All Your ...
To determine if your scan or query is running up against the limit, you need to look at the LastEvaluatedKey that is returned...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found