DynamoDB client behaves differently depending on whether client was directly created or obtained from a resource #2391
Labels
closing-soon
This issue will automatically close in 4 days unless further comments are made.
dynamodb
guidance
Question that needs advice or information.
Describe the bug
If you create a DynamoDB resource and later obtain its client instance
that client behaves differently from one that is created directly, as in
Code written for the latter breaks with the former. This was already reported in issue #2125. The issue was closed, but I believe the problem still prevails.
Steps to reproduce
A simple query will raise a
ClientError
when the client was obtained from the resource. You will need a table, otherwise the non-existent table exception will mask theClientError
.For simplicity, let's use the DynamoDB local server which has zero configuration. Download the local server and launch it with
Now add a table:
This query succeeds with a DynamoDB client obtained via
boto3.client()
:The same query fails if the client was obtained from a DynamoDB resource:
The above yields the following error:
The query only works with such a client if the
ExpressionAttributeValues
are deserialized:Expected behavior
I would expect the client to always behave in the same way. Regardless of whether you obtained it from a resource, it is still a client. Once you obtain the low-level client, you should use low-level representations, right?
The DynamoDB resource is a higher-level abstraction. It is very nicely Pythonic, especially in terms of implicit (de)serialization. I use it whenever I can, but sometimes you still need the client, because the resource doesn't cover the whole API.
Being able to obtain the client from the resource gives developers the best of both worlds.
Stack trace
The text was updated successfully, but these errors were encountered: