diff --git a/addons/google_account/models/google_service.py b/addons/google_account/models/google_service.py index 7905f4b074a..aaf3d865df7 100644 --- a/addons/google_account/models/google_service.py +++ b/addons/google_account/models/google_service.py @@ -146,14 +146,14 @@ class GoogleService(models.AbstractModel): res.raise_for_status() status = res.status_code - if int(status) in (204, 404): # Page not found, no response + if int(status) == 204: # Page not found, no response response = False else: response = res.json() try: - ask_time = datetime.strptime(res.headers.get('date'), "%a, %d %b %Y %H:%M:%S %Z") - except: + ask_time = datetime.strptime(res.headers.get('date', ''), "%a, %d %b %Y %H:%M:%S %Z") + except ValueError: pass except requests.HTTPError as error: if error.response.status_code in (204, 404): diff --git a/addons/google_calendar/models/res_users.py b/addons/google_calendar/models/res_users.py index d9c08f13fb4..d8693f633e7 100644 --- a/addons/google_calendar/models/res_users.py +++ b/addons/google_calendar/models/res_users.py @@ -97,6 +97,14 @@ class User(models.Model): self.ensure_one() if self.google_synchronization_stopped: return False + + # don't attempt to sync when another sync is already in progress, as we wouldn't be + # able to commit the transaction anyway (row is locked) + self.env.cr.execute("""SELECT id FROM res_users WHERE id = %s FOR NO KEY UPDATE SKIP LOCKED""", [self.id]) + if not self.env.cr.rowcount: + _logger.info("skipping calendar sync, locked user %s", self.login) + return False + full_sync = not bool(self.google_calendar_sync_token) with google_calendar_token(self) as token: try: