Repository navigation
[OU-FIX] mail: deduplicate link previews by source URL - #15
Merged
Merged
Conversation
Keep the lowest mail.link.preview id per source_url, re-point message links, and drop the extra link when one message had two previews of the same URL. The migrate decorator stays on migrate. Co-authored-by: André de Kock <[email protected]>
cursor
Bot
force-pushed
the
cursor/ou-20-08b-link-preview-dedupe-3e8f
branch
from
November 12, 2026 08:50
da981c4 to
f4865c1
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
Root cause
Odoo 20
mail.link.previewdeclaresmodels.UniqueIndex("(source_url)")(_unique_source_urlinaddons/mail/models/mail_link_preview.py). The same URL was stored more than once.mail.message.link.previewpoints at those rows and itself hasUNIQUE (message_id, link_preview_id). The upgrade analysis does not list this index (the generator does not emitmodels.UniqueIndexas a constraint line); the failure is the index create.Change
Mail pre-migration, before the index is created:
mail_link_preview.idper non-NULLsource_url.mail_message_link_previewrows that would collide on(message_id, link_preview_id)once they point at the kept preview.link_preview_idvalues.The work file notes this next to
mail.access_mail_link_preview_admin.Fork
20.0does not contain the mail migration yet (fork PR #4 does). This branch carries that pre-migration plus_dedupe_mail_link_preview. On a tree that already has PR #4, the only addition is that function, called at the start ofmigrate().Verification
Index and the message-link unique index were read from the Odoo 20 models.
ruffis clean. No database upgrade was run. No OCA pull request deduplicatesmail.link.preview.Upstream
Generic. Submit to OCA
20.0with the mail migration. The index is new in 20.0.Limitation
NULL
source_urlis not deduplicated (PostgreSQL unique indexes allow multiple NULLs; the field is required, so this is corrupt data). The kept row is the lowest id, not the most recently fetched preview. A foreign key other thanmail_message_link_preview.link_preview_idwould still block the delete; stock mail has no other one.