Google App Engine 数据存储问题:获取类型错误:尝试插入 DataSTore 时无法设置非属性

问题描述 投票:0回答:2

型号定义

class SeqNumbers(ndb.Model):
"""APNS Server -- SeqNumbers object that stores sequence number of stored messages between two devices"""
  SeqNumberStart = ndb.IntegerProperty(required=True)
  SeqNumberEnd = ndb.IntegerProperty(required=True)
  Sourcein = ndb.StringProperty
  Destin = ndb.StringProperty

添加到数据存储区的代码。这导致 类型错误:无法设置非属性 Sourcein(帖子末尾有完整错误)

任何有助于理解正在发生的事情的帮助将不胜感激。

data ={}
data['SeqNumberStart']=0
data['SeqNumberEnd']=0
data['key']=seqKey
data['Sourcein']='user_IOT'
data['Destin']='user_SmartHome'
SeqNumbers(**data).put()

GAE 日志中出现完整错误

E 02:08:17.725 Encountered unexpected error from ProtoRPC method implementation: TypeError (Cannot set non-property Sourcein)
  Traceback (most recent call last):
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
      response = method(instance, request)
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/endpoints-1.0/endpoints/api_config.py", line 1332, in invoke_remote
      return remote_method(service_instance, request)
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/remote.py", line 414, in invoke_remote_method
      response = method(service_instance, request)
    File "/base/data/home/apps/s~chatimegae/v1.388953439373110592/apns_server.py", line 588, in sendMsg
      SeqNumbers(**data).put()
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 2942, in __init__
      self._set_attributes(kwds)
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 2987, in _set_attributes
      raise TypeError('Cannot set non-property %s' % name)
  TypeError: Cannot set non-property Sourcein
google-app-engine google-cloud-datastore app-engine-ndb
2个回答
8
投票

您需要初始化Sourcein和Destin的属性。只需将括号放在末尾即可:

Sourcein = ndb.StringProperty()
Destin = ndb.StringProperty()

0
投票

就我而言,我有旧的

google.appengine.ext.db
,它使用
name
关键字参数来给出别名

class ModelClass:
    amt = db.FloatProperty(required=True, name="amount")

name:属性的存储名称。

默认情况下,使用在

Model
子类中分配的属性名称。

但是

google.appengine.ext.ndb
不支持
name
关键字参数

class ModelClass:
    amount = ndb.FloatProperty(required=True)

是的,

ndb
确实支持
name
关键字参数
...

我收到错误“无法设置非属性...”

ndb
,因为它使用了
getattr(cls, prop_name)
,但
db
检查了
self.properties()

© www.soinside.com 2019 - 2024. All rights reserved.