Repository navigation
[OU-FIX] mail: merge duplicate chats before member_indices unique index - #8
Merged
Merged
Conversation
Replayed onto 20.0 after the mail migration landed. Member-less chats become groups, duplicate chats fold onto the oldest, and the discuss.channel message count is checked. Co-authored-by: André de Kock <[email protected]>
cursor
Bot
force-pushed
the
cursor/ou-20-02-channel-member-indices-3e8f
branch
from
November 12, 2026 08:45
e8c2a84 to
7a58831
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
Creating the partial unique index
discuss_channel_member_indices_uniquefails:Odoo 20 also adds check constraints
discuss_channel_member_indices_chat_checkanddiscuss_channel_member_indices_channel_check. Older versions allowed several DM chats between the same members, so more than one chat would receive the samemember_indices.Root cause
discuss.channel.member_indicesis a new stored precomputed char (upgrade_analysis.txt:NEW isfunction: function, stored). Odoo 20DiscussChannel._member_indicesbuilds:Partner ids are sorted numerically, then guest ids. The unique index is
UNIQUE (member_indices) WHERE channel_type = 'chat'. Chats must have a non-empty value. Every other channel type must have NULL.Change
openupgrade_scripts/scripts/mail/20.0.1.19/pre-migration.py, before the model is initialised:openupgrade.add_columnsaddsmember_indicesso the compute does not run.string_agg ... ORDER BY sort_group, sort_id, partners then guests, numeric id). Non-chats are set back to NULL.""is rejected). Those rows becomechannel_type = 'group'with NULLmember_indices. Their messages stay. A group is private and the chat constraints do not apply.member_indices) keep the oldest (create_date, thenid). The others are merged into it:mail_messagewithmodel = 'discuss.channel'(res_id moved, rows not deleted)discuss_channel_member: one row per partner/guest;seen_message_idand, when the column still exists,fetched_message_idkeep the greater message idmail_followers, including subtype links, then the duplicate follower is droppedir_attachmentwithres_model = 'discuss.channel'discuss.channelare re-pointed (a self-parent that would point at itself is cleared)mail_messagerows withmodel = 'discuss.channel'before and after and raises if the count changed.The analysis lines for
member_indicesand the three new constraints are marked DONE.Fork
20.0does not contain the mail migration yet (fork PR #4 /20.0-integrationdoes). This branch therefore carries that pre-migration plus this step. On a tree that already has PR #4, the only addition is_merge_duplicate_chatsand its helpers, called at the start ofmigrate().Verification
The format was checked against Odoo 20
addons/mail/models/discuss/discuss_channel.py(_member_indices, the unique index and both checks). A small Python assertion locks the string form (partners [10, 2]and guests[3, 1]→p2,p10,g1,g3).ruffis clean. No database upgrade was run.No OCA pull request fills or deduplicates
member_indices.Upstream
Generic. Submit to OCA
20.0on top of the mail migration. Not applicable to 18.0 or 19.0.Limitations
mail_message.id. That matches creation order. A message inserted with an explicit lower id would be treated as older.DELETEthen fails the upgrade instead of dropping the related rows.model = 'discuss.channel'is moved. Rows still stored asmail.channelfrom a pre-16 database that never had that column rewritten are not touched. By 19.0 the model name isdiscuss.channel.