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

Wrap items in a set call for Model.batch_get #946

Merged
merged 4 commits into from
Jun 14, 2021

Conversation

jmphilli
Copy link
Contributor

@jmphilli jmphilli commented Jun 11, 2021

Workaround to avoid triggering server validation error:

{
    "Error": {
        "Message": "Provided list of item keys contains duplicates",
        "Code": "ValidationException"
    }
}

This doesn't update the underlying connection.Table or connection.Base batch_get_item call.

pynamodb/models.py Outdated Show resolved Hide resolved
@ikonst
Copy link
Contributor

ikonst commented Jun 14, 2021

Fixed the test: #948

jmphilli and others added 3 commits June 14, 2021 09:13
Co-authored-by: Ilya Konstantinov <ilya.konstantinov@gmail.com>
@Streadz
Copy link
Contributor

Streadz commented Jun 14, 2021

+1

@jmphilli jmphilli merged commit dc68e72 into pynamodb:master Jun 14, 2021
@sridhar562345
Copy link

Facing the below issue with batch_get, when JSONAttribute is used as hashkey

File "/home/user/Desktop/project_pynamo/venv/lib/python3.7/site-packages/pynamodb/models.py", line 338, in batch_get
    items = set(items)
TypeError: unhashable type: 'dict'

model

class UserMatchMap(Model):
    hash_key_compound_field = JSONAttribute(
        hash_key=True,
    )
   ...

sample data creation

hash_key_compound_field = {
            'user_id': 1,
            'status': "A",
            'game_id': 1
}

UserMatchMap(hash_key_compound_field=hash_key_compound_field).save()

Retrieving the hash keys using batch get raises the error

hash_key_compound_field = {
            'user_id': 1,
            'status': "A",
            'game_id': 1
}
UserMatchMap.batch_get(items=[hash_key_compound_field])

If we perform set on a list of dictionaries we face the above error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants