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

Index query with range key not working #25

Closed
abendig opened this issue May 22, 2014 · 8 comments
Closed

Index query with range key not working #25

abendig opened this issue May 22, 2014 · 8 comments

Comments

@abendig
Copy link

abendig commented May 22, 2014

There is an example of this at http://pynamodb.readthedocs.org/en/latest/indexes.html - the range key index query at the bottom of the page does not actually work - i.e. the following:

for item in TestModel.view_index.query('foo', view__gt=0):
    print("Item queried from index: {0}".format(item.view))

produces this exception:

Traceback (most recent call last):
  File "index_tests.py", line 54, in <module>
    for item in TestModel.view_index.query('foo', view__gt=0):
  File "/Users/alex/Development/pynamodb/lib/python2.7/site-packages/pynamodb/models.py", line 468, in query
    query_filters=query_filters
  File "/Users/alex/Development/pynamodb/lib/python2.7/site-packages/pynamodb/connection/table.py", line 171, in query
    select=select)
  File "/Users/alex/Development/pynamodb/lib/python2.7/site-packages/pynamodb/connection/base.py", line 882, in query
    raise QueryError("Failed to query items: {0}".format(response.content))
pynamodb.exceptions.QueryError: Failed to query items: {"__type":"com.amazon.coral.validate#ValidationException","message":"QueryFilter can only contain non-primary key attributes: Primary key attribute: view"}

Having explored this a little bit, it seems that the problem only occurs, if the range key attribute does not have a key on the model (hash or range). FWIW - the query appears to succeed with DynamoDB local.

@jlafon
Copy link
Contributor

jlafon commented May 22, 2014

Hi Alex,

I couldn't reproduce this, would you mind giving me the code you used? Here is what I tried: https://gist.github.com/jlafon/e8c2f787bbbafcfb041a

-Jharrod

@abendig
Copy link
Author

abendig commented May 22, 2014

Jharrod -

Like I said in my initial message, the query succeeds, if I use DynamoDB local. Using your example code, I can reproduce the exception, after removing the host = 'http://localhost:8000' line in TestModel.Meta. Obviously, it's unfortunate (and out of your hands) that DynamoDB local behaves differently than the remote version and this does make testing for it a bit harder.

Best,
Alex

@jlafon
Copy link
Contributor

jlafon commented May 22, 2014

OK, thanks for clarifying. I was able to reproduce this. The problem is the distinction between QueryFilter and KeyCondition in the query operation. I know how to fix it, but it's not trivial. I'll update this issue when it's done.

-Jharrod

@abendig
Copy link
Author

abendig commented May 22, 2014

Awesome. BTW: I hope to contribute actual code in the future instead of just issue reports.

@jlafon
Copy link
Contributor

jlafon commented May 22, 2014

Would you mind trying this out? Thanks.

@abendig
Copy link
Author

abendig commented May 22, 2014

That's a fair number of changes. I'm going to give this a spin later today and update this ticket.

@abendig
Copy link
Author

abendig commented May 23, 2014

I am no longer able to reproduce the problem with the current devel branch - neither using standard DynamoDB nor DynamoDB local.

@jlafon
Copy link
Contributor

jlafon commented May 23, 2014

Glad to hear it! I'll put out a bug fix release soon.

@jlafon jlafon closed this as completed May 27, 2014
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

No branches or pull requests

2 participants