问题
I am hoping to modify 1000 entities using task queue, as suggested Zig Mandel in my original question here: Google App Engine: Modifying 1000 entities
I have a UserAccount kind like this:
class UserAccount(ndb.Model):
email = ndb.StringProperty()
Some of the UserAccount email
s contain uppercases (example: JohnathanDough@email.com), and I would like to apply email.lower()
to every entity's email.
So I've set up a task queue like this:
class LowerEmailQueue(BaseHandler):
def get(self):
all_accounts = UserAccount.query().fetch()
for a in all_accounts:
taskqueue.add(url = '/lower-email', params = {'account_id': a.key.id()})
class LowerEmail(BaseHandler):
def post(self):
account_id = self.request.get('account_id')
account = UserAccount.get_by_id(int(account_id))
account.email = account.email.lower()
account.put()
app = webapp2.WSGIApplication([
('/', MainPage),
('/lower-email-queue', LowerEmailQueue),
('/lower-email', LowerEmail),
], debug=True)
I have not run this yet, because I want to prevent causing disastrous damage to my data. Should this work?
回答1:
No, in fact this will not do anything at all, because you don't do anything with the lowered email address. You need to actually assign it back to the entity.
account.email = account.email.lower()
来源:https://stackoverflow.com/questions/24761801/google-app-engine-modifying-1000-entities-using-taskqueue