[FIX] google_calendar: avoiding return of recordset when using ormcache
Before this commit: In some cases where some events won't sync to
Odoo properly you got the "Unable to use a closed cursor." error. The
problem is that `_from_google_ids` function returns a recordset, and the
underlying cursor may be closed.
Steps to reproduce the issue:
1. Create user_A and user_B in Odoo
2. Sync user_A and user_B with Google calendar
3. Create an event with user_B on the Google calendar
4. Run the "Google Calendar: synchronization" cron
5. Change the created event's owner to user_A on the Google calendar
6. Run the "Google Calendar: synchronization" cron
=> You will get this error on the log, and the event won't sync:
```
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/api.py", line 886, in get
return field_cache[record._ids[0]]
KeyError: 99
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/fields.py", line 1061, in __get__
value = env.cache.get(record, self)
File "/home/odoo/src/odoo/odoo/api.py", line 889, in get
raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'calendar.event(99,).google_id'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/odoo/src/odoo/addons/google_calendar/models/res_users.py", line 91, in _sync_all_google_calendar
user.with_user(user).sudo()._sync_google_calendar(google)
File "/home/odoo/src/odoo/addons/google_calendar/models/res_users.py", line 70, in _sync_google_calendar
synced_events = self.env['calendar.event']._sync_google2odoo(events - recurrences, default_reminders=default_reminders)
File "/home/odoo/src/odoo/addons/google_calendar/models/google_sync.py", line 147, in _sync_google2odoo
existing = google_events.exists(self.env)
File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 180, in exists
events.odoo_ids(env)
File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 88, in odoo_ids
found = self._load_odoo_ids_from_db(env, model)
File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 111, in _load_odoo_ids_from_db
mapping = {e.google_id: e.id for e in odoo_events} # {google_id: odoo_id}
File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 111, in <dictcomp>
mapping = {e.google_id: e.id for e in odoo_events} # {google_id: odoo_id}
File "/home/odoo/src/odoo/odoo/fields.py", line 1087, in __get__
recs._fetch_field(self)
File "/home/odoo/src/odoo/odoo/models.py", line 3276, in _fetch_field
self._read(fnames)
File "/home/odoo/src/odoo/addons/calendar/models/calendar_event.py", line 436, in _read
super()._read(fields)
File "/home/odoo/src/odoo/odoo/models.py", line 3343, in _read
cr.execute(query_str, params + [sub_ids])
File "<decorator-gen-20>", line 2, in execute
File "/home/odoo/src/odoo/odoo/sql_db.py", line 89, in check
raise psycopg2.OperationalError('Unable to use a closed cursor.')
```
The solution is to use ormcache on a function that returns the ids of the
events.
opw-3098799
closes odoo/odoo#109557
Signed-off-by:
Arnaud Joset <arj@odoo.com>