Skip to content

Commit

Permalink
[FIX] mail: do not crash if a partner has more than one mail.channel.…
Browse files Browse the repository at this point in the history
…partner

It is assumed that there is a unique mail.channel.partner per (channel, partner)
pair, yet there is nothing enforcing this restriction.
As a result field access on the channel partner crashes on field access.
  • Loading branch information
Nans Lefebvre authored and KangOl committed Feb 22, 2019
1 parent 0f4abc5 commit 8f8b945
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addons/mail/models/mail_channel.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def channel_seen(self):
self.ensure_one() self.ensure_one()
if self.channel_message_ids.ids: if self.channel_message_ids.ids:
last_message_id = self.channel_message_ids.ids[0] # zero is the index of the last message last_message_id = self.channel_message_ids.ids[0] # zero is the index of the last message
channel_partner = self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)]) channel_partner = self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)], limit=1)
if channel_partner.seen_message_id.id == last_message_id: if channel_partner.seen_message_id.id == last_message_id:
# last message seen by user is already up-to-date # last message seen by user is already up-to-date
return return
Expand Down Expand Up @@ -761,7 +761,7 @@ def channel_fetched(self):
if channel.channel_type != 'chat': if channel.channel_type != 'chat':
return return
last_message_id = channel.channel_message_ids.ids[0] # zero is the index of the last message last_message_id = channel.channel_message_ids.ids[0] # zero is the index of the last message
channel_partner = self.env['mail.channel.partner'].search([('channel_id', '=', channel.id), ('partner_id', '=', self.env.user.partner_id.id)]) channel_partner = self.env['mail.channel.partner'].search([('channel_id', '=', channel.id), ('partner_id', '=', self.env.user.partner_id.id)], limit=1)
if channel_partner.fetched_message_id.id == last_message_id: if channel_partner.fetched_message_id.id == last_message_id:
# last message fetched by user is already up-to-date # last message fetched by user is already up-to-date
return return
Expand Down

0 comments on commit 8f8b945

Please sign in to comment.