在调试我的应用程序时,我发现了一些意外行为。有谁知道为什么我会得到下面描述的结果?
from google.appengine.ext import ndb
class Person(ndb.Model):
name = ndb.StringProperty()
shared = ndb.BooleanProperty(default=False)
class Department(ndb.Model):
name = ndb.StringProperty()
persons = ndb.KeyProperty(kind=Person, repeated=True)
@property
def all_department_resources(self):
emp_list = self.persons
for p in Person.query().filter(Person.shared == True):
emp_list.append(p.key)
return emp_list
p1 = Person(name='Jane').put()
p2 = Person(name='Siri').put()
p3 = Person(name='Joe', shared=True).put()
Department(name='Finance',persons=[p1,p2]).put()
print '\n*First run*'
for d in Department.query():
print '>>' + d.name
for p in d.all_department_resources:
print p.get().name
print '\n*Second run:*'
for d in Department.query():
print '>>' + d.name
for p in d.all_department_resources:
print p.get().name
输出:
*First run*
>>Finance
Jane
Siri
Joe
*Second run:*
>>Finance
Jane
Siri
Joe
Joe
我的问题很简单:第二个乔是从哪里来的?