Open dhermes opened 10 years ago
THIS BAD BOY SHOULD BE A TRANSACTION
event = ndb.Key(cls, uid).get()
if event is not None:
changed = False
for attr, value in event_data.iteritems():
if getattr(event, attr) != value:
setattr(event, attr, value)
logging.info('{attr} changed for {uid}'.format(attr=attr, uid=uid))
changed = True
if current_user not in event.attendees: # pylint:disable-msg=E1103
event.attendees.append(current_user) # pylint:disable-msg=E1103
logging.info('attendees changed for {uid}'.format(uid=uid))
changed = True
success = True
if changed:
# pylint:disable-msg=E1103
success = event.update(credentials=credentials)
return event, not success
else:
# pylint:disable-msg=W0142
event = cls(key=ndb.Key(cls, uid), attendees=[current_user], **event_data)
success = event.insert(credentials=credentials)
return event, not success
If two users have the same item id at the same time, the ensuing race condition can cause orphaned events on GCal, since the item ID will be used as the datastore ID.
Should wrap
Event
writes into transactions and make sure thatgcal_edit
doesn't change after being set the first time. Sadly, this will likely cause an extra round trip for every write.NOTE: Migrated from Google Code Hosting