1. Ludia
  2. Untitled project
  3. dynamodb-mapper
Issue #26 new

autoincrement_int field usage results in exception on save

Alex Bendig
created an issue

Using autoincrement_int as the type for the hash_key of the table, an exception is raised on save().

Here's an excerpt of the exception traceback.

Traceback (most recent call last):
  [...]
  File "../lib/python2.7/site-packages/dynamodb_mapper-1.8.0-py2.7.egg/dynamodb_mapper/model.py", line 815, in save
    return self._save_autoincrement_hash_key()
  File "../lib/python2.7/site-packages/dynamodb_mapper-1.8.0-py2.7.egg/dynamodb_mapper/model.py", line 755, in _save_autoincrement_hash_key
    max_hash_item = Item(MAGIC_KEY)
  File "../lib/python2.7/site-packages/boto/dynamodb/item.py", line 42, in __init__
    self._hash_key_name = self.table.schema.hash_key_name
AttributeError: 'int' object has no attribute 'schema'

I think this is what's going on:

The signature of (boto/dynamodb.item.py) Item.init() looks like this:

__init__(self, table, hash_key=None, range_key=None, attrs=None)

It expects a table reference as first parameter, however in DynamoDBModel._save_autoincrement_hash_key(), line 755, no such reference is passed.

If we change that line from

max_hash_item = Item(MAGIC_KEY)

to

max_hash_item = Item(table, MAGIC_KEY)

then the exception is not raised, the item is correctly instantiated, the auto incrementing appears to work and saving succeeds.

Comments (2)

  1. Log in to comment