Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复此Python BadValueError(';属性%s是必需的';%self.name)_Python_Google App Engine_Google Cloud Datastore - Fatal编程技术网

如何修复此Python BadValueError(';属性%s是必需的';%self.name)

如何修复此Python BadValueError(';属性%s是必需的';%self.name),python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,我有这门课: class Contract(db.Model): book_number = db.IntegerProperty(required = True) initial_page = db.IntegerProperty(required = True) final_page = db.IntegerProperty(required = True) contract_type = db.StringProperty(required = True)

我有这门课:

class Contract(db.Model):
    book_number = db.IntegerProperty(required = True)
    initial_page = db.IntegerProperty(required = True)
    final_page = db.IntegerProperty(required = True)
    contract_type = db.StringProperty(required = True)
    parties = db.ListProperty(str)
    date = db.DateTimeProperty (required = True, auto_now = True, auto_now_add = True)
在我的代码的这一行:

 contract.parties = old_parties.append([str(person_id), person_condition])
从这个街区:

        (...)
        party = []
        contract_record = Contract(book_number = int(numBook),
                                   initial_page = int(numInitialPage),
                                   final_page = int(numFinalPage),
                                   contract_type = choosed_contract_type,
                                   parties = party)
        contract_record.put()
        contract_key = contract_record.key()
        contract_id = contract_record.key().id()

        submit_button = self.request.get('submit_button')

        if submit_button:
            if (person_name and valid_name(person_name)) and (user_SSN and valid_SSN(user_SSN)):
                person_record = Person(person_name = person_name,
                nacionality = user_nacionality,
                profession = user_profession,
                marital_status = user_marital_status,
                driver_license = int(user_driver_license),
                SSN = int(user_SSN),
                address = address)
                person_record.put()
                person_key = person_record.key()
                person_id = person_record.key().id()

                contract = Contract.get_by_id(contract_id)
                old_parties = contract.parties
                contract.parties = old_parties.append([str(person_id), person_condition])
                contract.put()
我得到了这个错误:

 File "C:\Users\Py\Desktop\contract\main.py", line 351, in post
    contract.parties = old_parties.append([str(person_id), person_condition])
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db\__init__.py", line 614, in __set__
    value = self.validate(value)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db\__init__.py", line 3435, in validate
    value = super(ListProperty, self).validate(value)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db\__init__.py", line 641, in validate
    raise BadValueError('Property %s is required' % self.name)
BadValueError: Property parties is required
我的目标是:创建一个对象
contract
,其
parties
属性中有一个空列表。在那之后,我想将新列表
[person\u id,person\u condition]
附加到这个空列表中,这样:
[[person\u id,person\u condition],[person\u id2,person\u condition 2],…]

我想知道是什么导致了这个错误,以及如何修复它以实现我的目标


谢谢你的帮助

我不确定这是否是导致您看到的GAE引擎的原因,但是
append
将适当地追加到列表中,并且不返回任何结果。所以您需要执行
contract.parties.append([str(person\u id),person\u condition])
。按照您的操作方式,您最终设置了
合同。各方
为无。

我不确定这是否是导致您看到的GAE引擎的原因,但是
append
会将其添加到适当的列表中并返回无。所以您需要执行
contract.parties.append([str(person\u id),person\u condition])
。按照你的方式,你最终建立了
合同。各方
都没有。

谢谢,布伦。不幸的是,现在我遇到了这个错误:
参与方列表中的项目必须都是基串实例
。字符串列表的项目可以是一个字符串列表吗?或者它只能接受字符串?@Pythonista'sApprentice:不清楚你在问什么。看起来您可能将其定义为一个字符串列表,但您正试图使其成为一个列表列表。当您执行
追加([str(person\u id),person\u condition])
时,您使列表包含一个项目,该项目是一个包含两个元素的列表。这就是您想要的,还是希望
各方
列表本身只有两个元素,每个元素都是字符串?@Pythonista'sApprentice:使用
.extend()
,而不是
.append()
,将列表中的所有项目添加到现有列表的末尾。将列表附加到列表将生成列表列表。谢谢,Bren。不幸的是,现在我遇到了这个错误:
参与方列表中的项目必须都是基串实例
。字符串列表的项目可以是一个字符串列表吗?或者它只能接受字符串?@Pythonista'sApprentice:不清楚你在问什么。看起来您可能将其定义为一个字符串列表,但您正试图使其成为一个列表列表。当您执行
追加([str(person\u id),person\u condition])
时,您使列表包含一个项目,该项目是一个包含两个元素的列表。这就是您想要的,还是希望
各方
列表本身只有两个元素,每个元素都是字符串?@Pythonista'sApprentice:使用
.extend()
,而不是
.append()
,将列表中的所有项目添加到现有列表的末尾。将列表附加到列表将生成列表列表。