pynamodb / PynamoDB

A pythonic interface to Amazon's DynamoDB
http://pynamodb.readthedocs.io
MIT License
2.46k stars 427 forks source link

simple get return attributes error #697

Open CrabbyPete opened 5 years ago

CrabbyPete commented 5 years ago

with Python 3.7 a simple get call id = '10015' item = Item.get(id)

Failed to get item: Parameter validation failed: Invalid type for parameter Key.item_id.S, value: [{'S': '1'}, {'S': '0'}, {'S': '0'}, {'S': '1'}, {'S': '0'}, {'S': '5'}], type: <class 'list'>, valid types: <class 'str'>

ikonst commented 5 years ago

It appears as if you're doing list(id) somewhere. Could you share more of the code?

CrabbyPete commented 5 years ago

I discovered what it was. I made the model field a list, when the underlying record had a map. I was simply doing a get item_new = Item.get(item['item_id'])

The model was

class Item(Model): class Meta: table_name = items

item_id         = UnicodeAttribute(hash_key=True)
unit_of_measure = UnicodeAttribute()
description     = UnicodeAttribute()
list_price      = UnicodeAttribute()
unit_cost       = UnicodeAttribute()
weight          = UnicodeAttribute()
volume          = UnicodeAttribute()
suppliers       = ListAttribute( of=Supplier )

but the actual record was suppliers = {}