Pythonで作成したプログラムをGoogleAppEngine(GAE)で動作させる際、『NeedIndexError: no matching index found.The suggested index for this query is:』というエラーが出る場合があります。
エラーの原因と対処法は以下から。
『NeedIndexError: no matching index found.』の意味
GAEにおいて、簡単なクエリ処理用のインデックスは自動生成されますが、複雑なクエリ処理用のインデックスは『index.yaml』に記述して定義する必要がある様です。
よって、『NeedIndexError: no matching index found.The suggested index for this query is:』というエラーの後に書かれている内容を『index.yaml』に記述する必要があります。
indexes: # AUTOGENERATED # This index.yaml is automatically updated whenever the dev_appserver # detects that a new type of query is run. If you want to manage the # index.yaml file manually, remove the above marker line (the line # saying "# AUTOGENERATED"). If you want to manage some indexes # manually, move them above the marker line. The index.yaml file is # automatically uploaded to the admin console when you next deploy # your application using appcfg.py. - kind: Sample properties: - name: hoge - name: moge - name: fuga
何故おかしな挙動になるのか
本エラーはWeb上にデプロイした環境で発生しますが、ローカル環境では発生せず、また時間を置いてWeb上で確認するとエラーが出ない場合があり、問題の原因を特定するのが困難な問題です。
これは『ローカル環境のindex.yamlは自動で上書き更新されるがWeb上のindex.yamlは上書き更新されない』のが原因です。
- Web上で上記エラーが発生する
- ローカル環境で同一条件で確認してみる
- ローカル環境でも同一のエラーになるがインデックスの内容が自動で『index.yaml』に上書きされる為、表側にエラーが表示されない(エラーが発生していない様に感じる)
- デプロイが失敗していたのかと考え、再度デプロイを行う
- 上書き更新された『index.yaml』がデプロイされる為、Web上でもエラーが出なくなる
この様な状態になるとエラー原因の特定が困難になります。
コメント