vavavr00m / boto

Automatically exported from code.google.com/p/boto
1 stars 0 forks source link

dynamodb2 Table.query function broken for seconday indexes #589

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. setup a dynamodb2 table with a hash key and global secondary index 
(secondary hash key)
2. add a row with the seconday index value set and save the result
3. query the table using the secondary index with the value of the secondary 
index set above

What is the expected output? What do you see instead?
we should get an iterator where next() returns the row we created above. 
instead, we get an exception, QueryError("You must specify more than one key to 
filter on."). 

What version of the product are you using? On what operating system?
latest (2.23.0) on mac osx. testing with dynamodb local.

Please provide any additional information below.
in order to fix this issue, I patched the table class and overrode the query 
method. I just check to see if an index is specified before throwing the 
exception that more than one key must be specified, since that restriction 
doesn't really make sense if an index is being used:

class PatchedDynamoTable(Table):

    def query(self, limit=None, index=None, reverse=False, consistent=False,
              attributes=None, max_page_size=None, **filter_kwargs):

        if not index and self.schema:
            if len(self.schema) == 1 and len(filter_kwargs) <= 1:
                raise exceptions.QueryError(
                    "You must specify more than one key to filter on."
                )

        if attributes is not None:
            select = 'SPECIFIC_ATTRIBUTES'
        else:
            select = None

        results = ResultSet(
            max_page_size=max_page_size
        )
        kwargs = filter_kwargs.copy()
        kwargs.update({
            'limit': limit,
            'index': index,
            'reverse': reverse,
            'consistent': consistent,
            'select': select,
            'attributes_to_get': attributes,
        })
        results.to_call(self._query, **kwargs)
        return results

Original issue reported on code.google.com by garrett....@affirm.com on 15 Jan 2014 at 10:46

GoogleCodeExporter commented 9 years ago
See this workaround for Version 2.34:
https://github.com/boto/boto/issues/2708

Original comment by philma...@googlemail.com on 12 Dec 2014 at 3:58