question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PreconditionFailed: 412 no matching index found. when using inequality filters

See original GitHub issue

I am using appengine to run my app and gcloud for accessing cloud datastore. I have gcloud model where i am storing username and date_time attribute.

but when i am doing this.

from gcloud.datastore.query import Query
from datetime import datetime
query = Query(kind="MyTable")
query.add_filter('username', '=', 'somevalue')
query.add_filter('date_time', '<', datetime.now())

iterator = query.fetch(limit=10)
records, more, cursor = iterator.next_page()
print records

I am getting the following exception.

 File "/Users/sathyanarrayanan/Desktop/app/services/cdr_helper.py", line 528, in fetch_last_users
    records, more, cursor = iterator.next_page()
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/query.py", line 388, in next_page
    transaction_id=transaction and transaction.id,
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/connection.py", line 257, in run_query
    datastore_pb.RunQueryResponse)
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/connection.py", line 108, in _rpc
    data=request_pb.SerializeToString())
  File "/Users/sathyanarrayanan/Desktop/app/gcloud/datastore/connection.py", line 85, in _request
    raise make_exception(headers, content, use_json=False)
PreconditionFailed: 412 no matching index found.

Below is my index file.

#File index.yaml

- kind: MyTable
  ancestor: yes
  properties:
  - name: date_time

- kind: MyTable
  ancestor: yes
  properties:
  - name: date_time
    direction: desc

- kind: MyTable
  ancestor: yes
  properties:
  - name: username
    direction: asc
  - name: date_time
    direction: desc

- kind: MyTable
  ancestor: yes
  properties:
  - name: username
    direction: asc
  - name: date_time

for more details: http://stackoverflow.com/questions/32607351/412-no-matching-index-found-while-executing-a-query-in-cloud-datastore

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dhermescommented, Sep 19, 2015

@plasmashadow I executed the following snippet in the dev server:

import datetime
from google.appengine.ext import ndb


class MyTable(ndb.Model):
    username = ndb.StringProperty()
    date_time = ndb.DateTimeProperty(auto_now=True)


parent_key = ndb.Key(MyTable, 'parent')
MyTable(parent=parent_key, username='somevalue').put()
MyTable(parent=parent_key, username='somevalue2').put()
MyTable(parent=parent_key, username='somevalue3').put()

q = MyTable.query(MyTable.username == 'somevalue',
                  MyTable.date_time < datetime.datetime.utcnow(),
                  ancestor=parent_key)
print(q.fetch())

The dev server automatically generated the following:

- kind: MyTable
  ancestor: yes
  properties:
  - name: username
  - name: date_time

If you are actually storing keys with ancestors, you’ll need to use the Query.ancestor setter.

0reactions
dhermescommented, Sep 24, 2015

Great to hear!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Cloud Datastore runQuery returning 412 "no matching ...
According to the docs, "a query can combine equality (EQUAL) filters for different properties, along with one or more inequality filters on a ......
Read more >
gcloud.exceptions.BadRequest: 400 - No matching index error ...
I am running a service in GCE which accesses cloud data store. I created an index for one of the Kinds in data...
Read more >
No Matching Index Found. Using Objectify - ADocLib
PreconditionFailed : 412 no matching index found. when using inequality filters ... Datastore: Filtering with equality fails with FailedPrecondition desc no ...
Read more >
Integrating Data With External Applications - IBM
Event Filter Class. Any Java classes you specify must be part of the application EAR file. An XSL file can be within the...
Read more >
Change History | AllegroGraph 6.4.4 - Franz Inc.
Using the Japanese text index tokenizer on a system that does not have ... Bug24665 - SPARQL queries with :dateTime inequality filters could...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found