[FIX] google_calendar: improve error handling when the record does not exists anymore.

Before this commit, the following traceback could be encountered when events were deleted:

```py
Traceback (most recent call last):
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 43, in called_after
    func(self.with_env(env), *args, **kwargs)
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 233, in _google_patch
    self._google_error_handling(e)
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 177, in _google_error_handling
    start = self.start and self.start.strftime('%Y-%m-%d at %H:%M') or _("undefined time")
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1087, in __get__
    raise MissingError("\n".join([
odoo.exceptions.MissingError: Record does not exist or has been deleted.
(Record: calendar.event(28241777,), User: XXXX)
```

X-original-commit: e77cbc639032e7f58345942330102b37e7a55971
Part-of: odoo/odoo#83040
This commit is contained in:
Arnaud Joset
2022-01-20 08:21:58 +00:00
parent 8847d391e4
commit 58addb377e
@@ -173,6 +173,12 @@ class GoogleSync(models.AbstractModel):
# We only handle the most problematic errors of sync events.
if http_error.response.status_code in (403, 400):
response = http_error.response.json()
if not self.exists():
reason = "Google gave the following explanation: %s" % response['error'].get('message')
error_log = "Error while syncing record. It does not exists anymore in the database. %s" % reason
_logger.error(error_log)
return
if self._name == 'calendar.event':
start = self.start and self.start.strftime('%Y-%m-%d at %H:%M') or _("undefined time")
event_ids = self.id