endpoints-proto-datastore ライブラリを使用して、アプリ エンジンで非常に単純なアプリケーションを作成しました。list メソッドに問題があります。JavaScript クライアントからデータを照会し、ユーザー入力に基づいて特定のエンティティを更新できるようにする必要があります。エンドポイントは予想どおりエンティティの配列を返していますが、同じ ID を共有する 2 つのエンティティが存在する場合があります。これにより、ID が実際にどのエンティティに属しているかがわからないため、データストア内のエンティティを確実に更新することができなくなります。
これは、データストアビューアツールのスクリーンショットです。
API Explorer を介して list メソッドを呼び出した結果:
200 OK
<headers omitted>
{
"items": [
{
"id": 5906470911296406000,
"prices": [
"$1000.00"
],
"options": [
"Chrome"
],
"title": "New Equipment",
"quantity": true
},
{
"id": 5906470911296406000,
"title": "New Equipment",
"quantity": false
}
]
}
API Explorer では ID が重複していることがわかりますが、データストアでは重複していません。これまでのところ、この動作を確実に生成することはできませんでしたが、上記のように非常によく似た 2 つのエンティティをデータストアに追加した場合にのみ発生するようです。
私のモデル:
class AvailableEquipment(EndpointsModel):
_message_fields_schema = ('id', 'title', 'options', 'prices', 'quantity')
title = ndb.StringProperty()
options = ndb.StringProperty(repeated=True)
prices = ndb.StringProperty(repeated=True)
quantity = ndb.BooleanProperty()
私のAPI:
@endpoints.api(name='equipment', version='v1', description='API for available equipment data')
class AvailableEquipmentAPI(remote.Service):
@AvailableEquipment.method(path='equipment', http_method='POST', name='insert')
def EquipmentInsert(self, equipment):
equipment.put()
return equipment
@AvailableEquipment.query_method(path='equipment', name='list')
def EquipmentList(self, query):
return query
これらのテストはすべて、ローカルの開発サーバーで実行されています。ご協力いただきありがとうございます。