Skip to content

[19.0][FIX] loyalty: clear stale mail.template.lang referencing removed _get_mail_partner#5629

Merged
pedrobaeza merged 1 commit into
OCA:19.0from
ledoent:19.0-fix-loyalty-stale-mail-template-fields
May 15, 2026
Merged

[19.0][FIX] loyalty: clear stale mail.template.lang referencing removed _get_mail_partner#5629
pedrobaeza merged 1 commit into
OCA:19.0from
ledoent:19.0-fix-loyalty-stale-mail-template-fields

Conversation

@dnplkndll
Copy link
Copy Markdown

@dnplkndll dnplkndll commented May 14, 2026

What

Add openupgrade_scripts/scripts/loyalty/19.0.1.0/pre-migration.py to clear
mail.template.lang on the two loyalty templates (mail_template_gift_card,
mail_template_loyalty_card) when it still references the removed
loyalty.card._get_mail_partner() helper.

Why

In 18.0 those two templates stored lang as an inline template:

```
mail_template.lang = '{{ object._get_mail_partner().lang }}'
```

The helper was removed from loyalty.card in 19.0. The 19.0
mail_template_data.xml does not touch the lang field — so on
mode=update load, ORM template-syntax validation evaluates the stale
value against a loyalty.card with no _get_mail_partner and raises:

```
AttributeError: 'loyalty.card' object has no attribute '_get_mail_partner'
```

This aborts the migration at loyalty/data/mail_template_data.xml:3.

How

Single SQL UPDATE that clears lang only on the two affected templates
(identified by XML ID via ir_model_data) and only when lang still
contains _get_mail_partner. That preserves any customer customisation
that may have replaced the stock value.

Two related 18.0 stale references are intentionally not handled in
pre-migration because the 19.0 XML already overwrites them on load:

  • mail.template.partner_to — reset via <field name=\"partner_to\" eval=\"False\"/>
  • mail.template.body_html — fully rewritten in the 19.0 XML

The 19.0 design replaces explicit per-template lang/partner_to with
use_default_to=True, delegating recipient + language resolution to the
model at send time.

Test plan

  • Repro confirmed: 18.0 DB with loyalty,sale_loyalty,pos_loyalty
    installed; -u all migration to 19.0 crashes as described without
    this patch.
  • With this patch: migration completes cleanly. ir_module_module
    shows loyalty | 19.0.1.0 | installed. Post-migration the two
    templates have lang='', partner_to='', use_default_to=True
    — same state as a fresh 19.0 install.
  • OCA CI green.

@OCA-git-bot OCA-git-bot added mod:openupgrade_scripts Module openupgrade_scripts series:19.0 labels May 14, 2026
@dnplkndll dnplkndll force-pushed the 19.0-fix-loyalty-stale-mail-template-fields branch from 68659a1 to 50d63b6 Compare May 14, 2026 20:36
@dnplkndll dnplkndll changed the title [FIX] loyalty: reset stale mail.template fields referencing removed _get_mail_partner [FIX] loyalty: clear stale mail.template.lang referencing removed _get_mail_partner May 14, 2026
@dnplkndll dnplkndll changed the title [FIX] loyalty: clear stale mail.template.lang referencing removed _get_mail_partner [19.0][FIX] loyalty: clear stale mail.template.lang referencing removed _get_mail_partner May 15, 2026
dnplkndll added a commit to ledoent/OpenUpgrade that referenced this pull request May 15, 2026
Add the merges introduced by today's PR series so the auto-built image
includes them and the lab can `OPENUPGRADE_PULL_POLICY=always` again:

 - 19.0-fix-hr-null-write-date                 (OCA#5628)
 - 19.0-fix-loyalty-stale-mail-template-fields (OCA#5629)
 - 19.0-fix-hr-obsolete-fields-cleanup         (OCA#5630)
 - 19.0-fix-partner-autocomplete-cleanup       (OCA#5631)
 - 19.0-fix-l10n-fr-cleanup                    (OCA#5632)

The companion lab repos.yaml is updated separately so local
`make sync-repos` matches.
Copy link
Copy Markdown
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, but too many lines of code for something that can be very easy on post-migration scripts:

for xmlid in ("mail_template_gift_card", "mail_template_loyalty_card"):
    template = env.ref(xmlid, False)
    if template:
        template.lang = False

And you can reduce the comments done with AI to something less verbose.

@dnplkndll
Copy link
Copy Markdown
Author

@pedrobaeza what do you think on the comments. in the past I would write the code fix and put the comment son the PR and never really but comments in the code. should there be any code comments? seems like they will just be obsolete and left later causing move confusion than good. but I do not recall reading any real convention on it.

@pedrobaeza
Copy link
Copy Markdown
Member

Code comments should clarify the "why" or summarize the "what" of the following code block, but not being too verbose stating the obvious, nor letting doubts about why things are done.

In this case, a simple docstring of the method can be Reset "lang" field for these records, as they were set in previous version in XML, but not in this one, and Odoo doesn't reset non present fields. Short, concise, and pretty explanatory, don't you think?

@dnplkndll dnplkndll force-pushed the 19.0-fix-loyalty-stale-mail-template-fields branch from 50d63b6 to 4fa0cf1 Compare May 15, 2026 11:21
@dnplkndll
Copy link
Copy Markdown
Author

Thanks for the review. Force-pushed the refactor:

  • Moved to post-migration.py (deleted the original pre-migration.py).
  • Used your env.ref + record.lang = False shape, four lines of code.
  • Stripped the file-level prose; reasoning stays in the PR description.

CI should re-run now.

@pedrobaeza pedrobaeza added this to the 19.0 milestone May 15, 2026
@pedrobaeza
Copy link
Copy Markdown
Member

You can put the docstring I recommended.

…mplates

The 18.0 loyalty mail_template_gift_card and mail_template_loyalty_card
both stored mail.template.lang as '{{ object._get_mail_partner().lang }}'.
The helper was removed in 19.0 and the 19.0 XML doesn't reset the lang
field, so on update load ORM template-syntax validation raises
AttributeError, aborting migration at
loyalty/data/mail_template_data.xml:3.

Reset the lang field to False on the two affected records in
post-migration. The 19.0 design (use_default_to=True) handles recipient
and language resolution at send time.
@dnplkndll dnplkndll force-pushed the 19.0-fix-loyalty-stale-mail-template-fields branch from 4fa0cf1 to 258b0a8 Compare May 15, 2026 11:37
@pedrobaeza pedrobaeza merged commit 8b85f42 into OCA:19.0 May 15, 2026
7 checks passed
dnplkndll added a commit to ledoent/OpenUpgrade that referenced this pull request May 16, 2026
Add the merges introduced by today's PR series so the auto-built image
includes them and the lab can `OPENUPGRADE_PULL_POLICY=always` again:

 - 19.0-fix-hr-null-write-date                 (OCA#5628)
 - 19.0-fix-loyalty-stale-mail-template-fields (OCA#5629)
 - 19.0-fix-hr-obsolete-fields-cleanup         (OCA#5630)
 - 19.0-fix-partner-autocomplete-cleanup       (OCA#5631)
 - 19.0-fix-l10n-fr-cleanup                    (OCA#5632)

The companion lab repos.yaml is updated separately so local
`make sync-repos` matches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:openupgrade_scripts Module openupgrade_scripts series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants