0

次の自己参照 EndpointsModel を作成しようとしています (トリック_fix_up_properties()はここから取得されます: https://groups.google.com/forum/#!topic/appengine-ndb-discuss/1FmgEVK7JNM ):

class EventFieldSchema(EndpointsModel):
  name = ndb.StringProperty(required=True)
  type = msgprop.EnumProperty(EventType, required=True)

EventFieldSchema.nested_fields = ndb.LocalStructuredProperty(EventFieldSchema,repeated=True)
EventFieldSchema._fix_up_properties()

これはデータストア モデルで機能しますが、残念ながら、nested_fieldsフィールドは ProtoRPC メッセージに含まれません。最後に次の行を追加して、メッセージ フィールド スキーマを手動で指定しようとしました。

EventFieldSchema._message_fields_schema = ('name', 'type', 'nested_fields')

しかしその後、app-engine が失敗し、ループに入り、EventFieldSchema を ProtoRPC フィールドに変換しようとします:

Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
  handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
  handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
  obj = __import__(path[0])
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/main.py", line 3, in <module>
  from er.api.event import EventRegistryApi
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/er/api/event.py", line 17, in <module>
  class EventRegistryApi(remote.Service):
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/er/api/event.py", line 23, in EventRegistryApi
  name='%s.insert' % RESOURCE_NAME)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/util.py", line 170, in positional_wrapper
  return wrapped(*args, **kwargs)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1359, in method
  kwargs[REQUEST_MESSAGE] = cls.ProtoModel(fields=request_fields)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1031, in ProtoModel
  allow_message_fields=allow_message_fields)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 969, in _MessageFields
  proto_attr = to_proto(prop, field_index)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/utils.py", line 137, in StructuredPropertyToProto
  property_proto = property_proto_method()
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1031, in ProtoModel
  allow_message_fields=allow_message_fields)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 969, in _MessageFields
  proto_attr = to_proto(prop, field_index)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/utils.py", line 137, in StructuredPropertyToProto
  property_proto = property_proto_method()
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1031, in ProtoModel

これは EndpointsModel のバグですか? 自己参照 EndpointsModels を定義する「適切な」方法は何ですか?

4

1 に答える 1

0

EndpointsModel の自己参照で同じ問題が発生します。

class UnitsProtoModel(EndpointsModel):
  """ ProtoRPC Model for storing/retrieving a unit. """

  _message_fields_schema = ('id', 'uic', 'parent_id', 'branch_id', 'name')

  uic = ndb.StringProperty(required=True)
  parent_id = ndb.StringProperty(required=True, default=None)
  branch_id = ndb.StringProperty(required=True)
  name = ndb.StringProperty(required=True)
  abbreviated_name = ndb.StringProperty(default="")
  flagged = ndb.BooleanProperty(default=False)
  message = ndb.StringProperty(default="")
  unit_created_at = ndb.DateTimeProperty(auto_now_add=True)


class UnitsCollection(EndpointsModel):
  items = messages.MessageField(UnitsProtoModel, 1, repeated=True)

エラー メッセージ: `File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine- default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0/protorpc/util.py", line 170, in positional_wrapper

return wrapped(*args, **kwargs)

ファイル "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0/protorpc/messages.py"、1531 行目、init内

raise FieldDefinitionError('Invalid message class: %s' % message_type)

FieldDefinitionError: 無効なメッセージ クラス:

UnitsProtoModel<abbreviated_name=StringProperty('abbreviated_name', default=''),    branch_id=StringProperty('branch_id', required=True), flagged=BooleanProperty('flagged', default=False), message=StringProperty('message', default=''), name=StringProperty('name', required=True), owner=UserProperty('owner'), parent_id=StringProperty('parent_id', required=True), uic=StringProperty('uic', required=True), unit_created_at=DateTimeProperty('unit_created_at', auto_now_add=True)>`
于 2014-12-19T16:35:30.090 に答える