1

I'm working on a voting app, where the user can upload a list of email addresses for all of the voters. After doing some error checking, I create a Voter entity for each voter. Since there can be a large number of voters, I create the Voter entities in a taskqueue to avoid the 30 second limit and the task looks like this:

    put_list = []
    for email, id in itertools.izip(voter_emails, uuids):
        put_list.append(Voter(election = election,
                              email = email,
                              uuid = id))
    election.txt_voters = ""
    put_list.append(election)
    db.put(put_list)

This task, however, isn't idempotent. Is there a way to make this task idempotent? Or is there a better way to do this?

new name
  • 15,861
  • 19
  • 68
  • 114

1 Answers1

1

use a key_name rather than a uuid property to prevent creating duplicate voter entities.

Chris Farmiloe
  • 13,935
  • 5
  • 48
  • 57
  • I like this idea, but I'm concerned with the number of datastore calls. In the above code there is just one put. To use named keys, I think I'd have to call get_or_insert for a each voter (a very large number) plus the one put. Is it possible to do bulk operations with named keys? – new name Jul 17 '11 at 12:28
  • 1
    you should be able to use `put()` even with a key_name, and and the new instance will replace all of the properties on the old. It's not clear what you need the uuid's for at all. I would probably do this something like `Voter(parent=election, key_name=email)` – SingleNegationElimination Jul 17 '11 at 15:21
  • @TokenMacGuy, using email as the key name is a good idea. I need the UUID to prevent voter fraud (UUID is sent to voter's email). I think I don't want the Voter to be in the same entity group as the Election but I'm going to ask another question about that. – new name Jul 17 '11 at 23:49
  • @TokenMacGuy, actually I can't use the email as the key name since it isn't guaranteed to be unique (the same email could be used in two different elections). I guess I could prepend some kind of unique ID for the election. – new name Jul 18 '11 at 00:21