autoincrement_int field usage results in exception on save

Create issue
Issue #26 new
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/", 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/", line 755, in _save_autoincrement_hash_key
    max_hash_item = Item(MAGIC_KEY)
  File "../lib/python2.7/site-packages/boto/dynamodb/", 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/ 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)


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. √Čric Araujo

    Thanks for the analysis. Could you turn the fix into a patch/commit/pull request, with a test?

  2. Log in to comment