votergroup = db.GqlQuery("SELECT * FROM Voter WHERE lastname = :1", 'AGEE')
for voter in votergroup:
voter.email = 'testemail@testemail.com'
db.put(votergroup)
The above code doesn't seem to be updating the records as it shows in the appengine documentation. I also tried using a query object to no avail. I know votergroup is pulling records, because I did a count on the object when debugging and it showed 10 records. In fact, before the db.put, I looped through voter.email, and it seems like the variable was set. However, the change never seems to make it back to the db.
Does anyone know what I might be doing wrong?
You need to call
fetch()
on the query you create withdb.Query()
to have it return a list of entities. You can then callput(list_of_entities)
to persist them all. That looks like this:If you don't call
fetch()
on the query, you can still iterate over the results, and a datastore RPC will be made to retrieve small batches as they are needed. Callingput()
on the query doesn't do anything, but you can still perform actions on each entity inside the loop.Note that this does one datastore calls for each entity, plus one call for each batch being iterated over. It's much better to use
fetch()
unless you don't know how many items will be returned.You can use cursors to break fetches up into larger chunks. I believe, though I can't find any proof, that
fetch()
has a limit of 1000 entities.Try this instead:
I don't think there is a way to do mass edits with the app engine.