Inconsistent results calling events_update

330 views
Skip to first unread message

Mac Martine

unread,
Apr 23, 2012, 8:05:30 PM4/23/12
to google-ca...@googlegroups.com
I'm getting inconsistent results updating events with the Google Calendar API using the Ruby client.

To verify the oddities I've created loops to updated the same exact event 10 times in a row with the same data. Sometimes it passes, other times it fails with 'Precondition Failed' for the If-Match.

To be clear, the loop isn't what's causing the failures -- in other words, if I just call update once at a time I still get inconsistent results.

It also seems weird that it returns different etags for the same event, doesn't it?

Any idea what's up?

    for i in 0..10
      remote_event  = google_client.events_get(record.calendar_id, record.event_id)
      Rails.logger.debug("\n#{i}. \t #{remote_event.etag} ")
      event_hash    = self.to_remote_event_hash(google_client)
      result        = google_client.events_update(record.calendar_id, remote_event)
      status        = result.data.id.nil? ? "FAILED" : "PASSED"
      Rails.logger.debug("#{status}")
    end

The failure in the results below is:

    <Google::APIClient::Schema::Calendar::V3::Event:0x3fca398f3188 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"conditionNotMet", "message"=>"Precondition Failed", "locationType"=>"header", "location"=>"If-Match"}], "code"=>412, "message"=>"Precondition Failed"}}>


output

    0.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    1.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    2.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    3.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    FAILED    
   
    4.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    5.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    6.      "DtwDXDyBz5ZZP0Bus85WBYkv-64/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    FAILED    
   
    7.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    8.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    9.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    
   
    10.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pDMHJvcnVKaEVBQUFBQUFBQUFBQT09"
    PASSED    

Sandip Shah

unread,
Apr 23, 2012, 10:27:03 PM4/23/12
to google-ca...@googlegroups.com
Hi Mac,

Interesting ...

I believe that the API Console says that one can do 5 api calls per second per user.  Most likely you are way beyond that limit with such sort of loops - so results are bound to be erratic.

Also, the API might be checking and comparing the data set before the update - if there is no change in the data (as in your case), no need to update it (also, it might be giving you a cached copy since there are no updates).

I don't know why you are doing such a loop, but what you may want to do is either change a value, or increment it, or do something similar so that the API is forced to save the update.  Also, you may want to insert a small delay, let's say 3 seconds, in between each iteration.

Post the results of what you find after that.

Sandip

Ray Baxter

unread,
Apr 23, 2012, 10:30:02 PM4/23/12
to google-ca...@googlegroups.com
When you pass in the incorrect etag, the update cannot happen because the etags do not match. This is the meaning of the 412, Precondition Failed response code.

You aren't verifying that the google_client.events_get call is successfully returning, so in all likelihood that failing call was unsuccessful.

Ray


--
You received this message because you are subscribed to the Google Groups "Google Calendar API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-calendar-api/-/hAoLLeLaiDoJ.
To post to this group, send email to google-ca...@googlegroups.com.
To unsubscribe from this group, send email to google-calendar...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.

Mac Martine

unread,
Apr 24, 2012, 12:05:33 AM4/24/12
to google-ca...@googlegroups.com


@Sandip,
Good to know about the limit, but as I mentioned the loop was only to more clearly show the inconsistencies, and even if I make the calls minutes apart it's a crap-shoot whether or not they pass. Below are the results from calls 5 seconds apart, and changing the event summary each time. Isn't it also very strange that the etag often doesn't change, and when it does, it reverts to the previous etag on the next call? I would expect repeat etags to be ridiculously rare.

@Ray,
I understand what the error means, but I have no idea why I'm getting it sometimes and not others. I am verifying the response of the call -- that's what 'FAILED' means in my results. I display 'FAILED' if the response.data does not have an id, which means it returned an error, in this case 412.

Here are the new results:


    for i in 0..10
      remote_event  = google_client.events_get(record.calendar_id, record.event_id)
      remote_event["summary"] = i.to_s

      Rails.logger.debug("\n#{i}. \t #{remote_event.etag} ")
      result        = google_client.events_update(record.calendar_id, remote_event)
      status        = result.data.id.nil? ? "FAILED" : "PASSED"
      Rails.logger.debug("#{status}")
      sleep 5
    end

0.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q09peS1aUHVKaEVBQUFBQUFBQUFBQT09"
FAILED    

1.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q09peS1aUHVKaEVBQUFBQUFBQUFBQT09"
PASSED    

2.      "DtwDXDyBz5ZZP0Bus85WBYkv-64/Q0tqY2dKVHVKaEVBQUFBQUFBQUFBQT09"
FAILED    

3.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0tqY2dKVHVKaEVBQUFBQUFBQUFBQT09"
FAILED    

4.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0tqY2dKVHVKaEVBQUFBQUFBQUFBQT09"
PASSED    

5.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q1Bqb2daVHVKaEVBQUFBQUFBQUFBQT09"
PASSED    

6.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q09pWGdwVHVKaEVBQUFBQUFBQUFBQT09"
FAILED    

7.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q09pWGdwVHVKaEVBQUFBQUFBQUFBQT09"
PASSED    

8.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q01qMWdwVHVKaEVBQUFBQUFBQUFBQT09"
PASSED    

9.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0xpa2c1VHVKaEVBQUFBQUFBQUFBQT09"
PASSED    

10.      "c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0tqVGc1VHVKaEVBQUFBQUFBQUFBQT09"
PASSED    
Completed 200 OK in 70984ms (Views: 0.9ms | ActiveRecord: 6.0ms)

Thanks!
Mac
To post to this group, send email to google-calendar-api@googlegroups.com.
To unsubscribe from this group, send email to google-calendar-api+unsub...@googlegroups.com.

Mac Martine

unread,
Apr 24, 2012, 12:08:48 AM4/24/12
to google-ca...@googlegroups.com
I just realized I didn't show my events_update method:

  def events_update(calendar_id, event)
    client.execute( :api_method => calendar_service.events.update,
                    :parameters => {'calendarId' => calendar_id, 'eventId' => event.id},
                    :body => JSON.dump(event),
                    :headers => {'Content-Type' => 'application/json', 'If-Match' => event.etag})
  end

Ray Baxter

unread,
Apr 24, 2012, 2:48:15 AM4/24/12
to google-ca...@googlegroups.com
I'm suggesting that your google_client.events_get call failed. 

Your update failed too, because you had bad etags from your events_get method, but that is a consequence of the first failure.

As to why, this is the internet. Remote calls will fail.

Ray

To view this discussion on the web visit https://groups.google.com/d/msg/google-calendar-api/-/kWlo7ZZOpXwJ.

To post to this group, send email to google-ca...@googlegroups.com.
To unsubscribe from this group, send email to google-calendar...@googlegroups.com.

Mac Martine

unread,
Apr 24, 2012, 11:46:38 AM4/24/12
to google-ca...@googlegroups.com
Ah. My events_get calls look fine from what I can tell. Here's the result of an events_get call (I just replaced some long codes with 'x''s) where the subsequent events_update call failed with a 412.

#<Google::APIClient::Schema::Calendar::V3::Event:0x3fc2ce2de1c0 DATA:{"kind"=>"calendar#event", "etag"=>"\"c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pENmtLanVKaEVBQUFBQUFBQUFBQT09\"", "id"=>"xxxxx", "status"=>"confirmed", "htmlLink"=>"https://www.google.com/calendar/event?eid=xxxxx", "created"=>"2012-04-23T19:13:19.000Z", "updated"=>"2012-04-24T15:42:02.000Z", "summary"=>"1", "creator"=>{"email"=>"xx...@gmail.com"}, "organizer"=>{"email"=>"xx...@group.calendar.google.com", "displayName"=>"Kitchen"}, "start"=>{"dateTime"=>"2012-04-24T18:00:00Z", "timeZone"=>"America/Los_Angeles"}, "end"=>{"dateTime"=>"2012-04-24T19:00:00Z", "timeZone"=>"America/Los_Angeles"}, "iCalUID"=>"xx...@google.com", "sequence"=>17, "reminders"=>{"useDefault"=>true}}>

#<Google::APIClient::Schema::Calendar::V3::Event:0x3fc2ce2bcd04 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"conditionNotMet", "message"=>"Precondition Failed", "locationType"=>"header", "location"=>"If-Match"}], "code"=>412, "message"=>"Precondition Failed"}}>
Ray

To unsubscribe from this group, send email to google-calendar-api+unsubscribe...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.

--
You received this message because you are subscribed to the Google Groups "Google Calendar API" group.

Mac Martine

unread,
Apr 24, 2012, 12:20:11 PM4/24/12
to google-ca...@googlegroups.com
Here's the most simplified way to show the problem that I can find. I do this at a breakpoint in my app. I waited about a minute after any other calls, my calendar is not open anywhere else, etc.

In one case when I did this, a second call to events.update worked (and it still had the same etag that had just failed!)

--> (rdb:30) remote_event  = google_client.client.execute( :api_method => google_client.calendar_service.events.get, :parameters => {'calendarId' => record.calendar_id, 'eventId' => remote_event.id}).data

#<Google::APIClient::Schema::Calendar::V3::Event:0x3ff27b0eabc0 DATA:{"kind"=>"calendar#event", "etag"=>"\"xxxxx\"", "id"=>"xxxxx", "status"=>"confirmed", "htmlLink"=>"https://www.google.com/calendar/event?eid=xxxxx", "created"=>"2012-04-23T19:13:19.000Z", "updated"=>"2012-04-24T16:12:00.000Z", "summary"=>"0", "creator"=>{"email"=>"xx...@gmail.com"}, "organizer"=>{"email"=>"xx...@group.calendar.google.com", "displayName"=>"Kitchen"}, "start"=>{"dateTime"=>"2012-04-24T14:00:00Z", "timeZone"=>"America/Los_Angeles"}, "end"=>{"dateTime"=>"2012-04-24T15:00:00Z", "timeZone"=>"America/Los_Angeles"}, "iCalUID"=>"xx...@google.com", "sequence"=>19, "reminders"=>{"useDefault"=>true}}>

--> (rdb:30) google_client.client.execute( :api_method => google_client.calendar_service.events.update, :parameters => {'calendarId' => record.calendar_id, 'eventId' => remote_event.id}, :body => JSON.dump(remote_event), :headers => {'Content-Type' => 'application/json', 'If-Match' => remote_event.etag}).data
#<Google::APIClient::Schema::Calendar::V3::Event:0x3ff279a17d44 DATA:{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"conditionNotMet", "message"=>"Precondition Failed", "locationType"=>"header", "location"=>"If-Match"}], "code"=>412, "message"=>"Precondition Failed"}}>





On Tuesday, April 24, 2012 8:46:38 AM UTC-7, Mac Martine wrote:
Ah. My events_get calls look fine from what I can tell. Here's the result of an events_get call (I just replaced some long codes with 'x''s) where the subsequent events_update call failed with a 412.

#<Google::APIClient::Schema::Calendar::V3::Event:0x3fc2ce2de1c0 DATA:{"kind"=>"calendar#event", "etag"=>"\"c5Pj5ZZfo_-lyDNwU2zL3j-mMCM/Q0pENmtLanVKaEVBQUFBQUFBQUFBQT09\"", "id"=>"xxxxx", "status"=>"confirmed", "htmlLink"=>"https://www.google.com/calendar/event?eid=xxxxx", "created"=>"2012-04-23T19:13:19.000Z", "updated"=>"2012-04-24T15:42:02.000Z", "summary"=>"1", "creator"=>{"email"=>"xxxxx@gmail.com"}, "organizer"=>{"email"=>"xxxxx@group.calendar.google.com", "displayName"=>"Kitchen"}, "start"=>{"dateTime"=>"2012-04-24T18:00:00Z", "timeZone"=>"America/Los_Angeles"}, "end"=>{"dateTime"=>"2012-04-24T19:00:00Z", "timeZone"=>"America/Los_Angeles"}, "iCalUID"=>"xx...@google.com", "sequence"=>17, "reminders"=>{"useDefault"=>true}}>

Mac Martine

unread,
Apr 25, 2012, 12:06:30 PM4/25/12
to google-ca...@googlegroups.com

Any other suggestions here? I'm out of ideas.
Thanks.



On Tuesday, April 24, 2012 9:20:11 AM UTC-7, Mac Martine wrote:
Here's the most simplified way to show the problem that I can find. I do this at a breakpoint in my app. I waited about a minute after any other calls, my calendar is not open anywhere else, etc.

In one case when I did this, a second call to events.update worked (and it still had the same etag that had just failed!)

--> (rdb:30) remote_event  = google_client.client.execute( :api_method => google_client.calendar_service.events.get, :parameters => {'calendarId' => record.calendar_id, 'eventId' => remote_event.id}).data

#<Google::APIClient::Schema::Calendar::V3::Event:0x3ff27b0eabc0 DATA:{"kind"=>"calendar#event", "etag"=>"\"xxxxx\"", "id"=>"xxxxx", "status"=>"confirmed", "htmlLink"=>"https://www.google.com/calendar/event?eid=xxxxx", "created"=>"2012-04-23T19:13:19.000Z", "updated"=>"2012-04-24T16:12:00.000Z", "summary"=>"0", "creator"=>{"email"=>"xxxxx@gmail.com"}, "organizer"=>{"email"=>"xxxxx@group.calendar.google.com", "displayName"=>"Kitchen"}, "start"=>{"dateTime"=>"2012-04-24T14:00:00Z", "timeZone"=>"America/Los_Angeles"}, "end"=>{"dateTime"=>"2012-04-24T15:00:00Z", "timeZone"=>"America/Los_Angeles"}, "iCalUID"=>"xx...@google.com", "sequence"=>19, "reminders"=>{"useDefault"=>true}}>

Sreedevi Ajith

unread,
Jun 14, 2012, 4:13:42 AM6/14/12
to google-ca...@googlegroups.com
Hi Martine,

Did  you find a solution for this issue? I am also facing the same situation.If you found any solution,please share it here.

Thanks,
Sreedevi

Sébastien Barré

unread,
Aug 24, 2012, 11:42:01 AM8/24/12
to google-ca...@googlegroups.com
Hi Mac Martine,
thanks for investigating this and reporting the results in so many details !
I confirm I get the same problem.
Maybe one element I can bring, without being sure though: I think that the event Etag is divided in an event-specific part (right-side of the etag), and a calendar specific part (left-side of the etag).  It seems indeed that the problem happens only for events that are shared in several calendars, either by associating multiple calendars to the same event, or by inviting other participants.

This may explain why the first part of the etag changes depending on what login is used to request the event. However I understand that you use the same login for all requests. Maybe there is some mess due to multiple calendars sharing the event in the same account ? (that may be my case but I need further testing to verify that the condition is always verified).

Currently, in case of failure, I just postpone the update to later as it always eventually works, but I am clearly interested in getting the solution if someone finds it.
Reply all
Reply to author
Forward
0 new messages