3

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

これらのテストはすべて、ローカルの開発サーバーで実行されています。ご協力いただきありがとうございます。

4

2 に答える 2

2

最新の SDK を使用していますか? 以前のバージョンでは、JavaScript フロートで保存するには大きすぎる ID が生成されていたため、2 つの一意の ID が同じ値に丸められたり切り捨てられたりする可能性がありました。ID が 000 で終わるということは、これが原因である可能性があることを示唆しています。最新バージョンとライブ環境では、この問題は発生しません。

于 2013-06-06T23:11:22.937 に答える
1

It's due to the fact that Javascripts stores the numbers using 64-bit floats.

They already changed that and actually in the version 1.8.0 they fixed it and the auto ID is smaller so they can be represented in JSON. In the latest blog post they announced that in the upcoming version this will be guaranteed and the scattered auto IDs will be by default.

于 2013-06-06T23:14:51.533 に答える