エンドポイントを使用すると、protorpc
から奇妙なエラーが発生します。このコードで:エンドポイントAPI - protorpc検証エラー
class Application(EndpointsModel):
_message_fields_schema = ('id', 'name')
created = ndb.DateTimeProperty(auto_now_add=True)
name = ndb.StringProperty()
roles = ndb.IntegerProperty(repeated=True)
updated = ndb.DateTimeProperty(auto_now=True)
owner = ndb.KeyProperty(kind='User')
@API.api_class(resource_name="application")
class ApplicationApi(protorpc.remote.Service):
@Application.method(http_method="GET",
request_fields=('id',),
name="get",
path="applications/{id}")
def ApplicationGet(self, instance):
if not instance.from_datastore:
raise endpoints.NotFoundException("Application not found.")
return instance
@Application.query_method(http_method="GET",
query_fields=('limit', 'order', 'pageToken'),
name="list",
path="applications")
def ApplicationList(self, query):
return query
私は次のようにapplication.get()
誤りがある呼び出します(full trace here):(full trace here):次のように
TypeError: Can only copy from entities of the exact type Application. Received an instance of Application.
とapplication.list()
エラーを呼び出すためには、ある
ValidationError: Expected type
<class '.Application'>
for field items, found<Application name: u'test'>
(type<class '.Application'>
)
これは何が原因でしょうか?私の他のモデルはかなり同じコード(ちょうど異なるプロパティ)で正常に動作します。
これらのトレースは、クラス(タイプ)オブジェクト 'Application'の代わりに' Application'のインスタンスを使用しているようです。あなたのコードのどこかで 'Application()'を使っていないのですか? –
私はどこでもそれを使用していません - 関連するすべてのコードが質問にあります。私はクラス 'ApplicationApi(BaseRemoteService)'を拡張していますが、そこにはアプリケーションの言及がありません。また、POST APIメソッド(動作します...)がありますが、すべてを削除しても、 OPのコード。 – Sasxa
これは暗闇の中のショットですが、 'EndpointsModel'をサブクラス化する前に' Application'サブクラス 'ndb.Model'を実行しましたか?すべての 'Application'エンティティをループして、それらに対して' put'を再度実行してみてください。あなたが渡したキーがエンティティを取得すると思っていますが、継承チェーンについては、 '__class__'フィールドが一致しないことがあります。 –