[FIX] fetchmail_attach_from_folder: handle raise_exception in fetch_mail for Odoo 18#3601
[FIX] fetchmail_attach_from_folder: handle raise_exception in fetch_mail for Odoo 18#3601fsmw wants to merge 2 commits into
Conversation
…ail for Odoo 18 In Odoo 18, fetch_mail() accepts a raise_exception parameter, but the base fetchmail.server model in Odoo 17 doesn't have this parameter. This fix filters out raise_exception from kwargs before passing to super() to avoid TypeError. Closes OCA#3509
|
Hi @NL66278, |
There was a problem hiding this comment.
Pull request overview
This PR aims to make fetchmail_attach_from_folder compatible with Odoo 18’s updated fetchmail.server.fetch_mail() API by preventing raise_exception from causing a TypeError when delegating to a parent implementation that doesn’t accept it.
Changes:
- Filters
raise_exceptionout ofkwargsbefore calling the parentfetch_mail()implementation. - Keeps folder-based fetching behavior unchanged (
folder_ids.fetch_mail()still runs per server).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # In Odoo 18, fetch_mail accepts raise_exception parameter | ||
| # Don't pass it unless explicitly provided | ||
| super_kwargs = { | ||
| k: v for k, v in kwargs.items() if k != "raise_exception" | ||
| } | ||
| result = result and super(FetchmailServer, this).fetch_mail( | ||
| **super_kwargs | ||
| ) |
There was a problem hiding this comment.
raise_exception is being stripped unconditionally before calling super().fetch_mail(). On Odoo versions where the parent method does support raise_exception, this will ignore the caller’s intent (e.g., Odoo 18 cron passes raise_exception=False) and can change behavior by falling back to the parent default. Consider forwarding raise_exception when supported and only dropping it for older parents (e.g., call super().fetch_mail(**kwargs) and, if a TypeError for an unexpected keyword is raised, retry after removing raise_exception). Also the inline comment says “Don’t pass it unless explicitly provided”, but the current code never passes it even when explicitly provided.
| # In Odoo 18, fetch_mail accepts raise_exception parameter | |
| # Don't pass it unless explicitly provided | |
| super_kwargs = { | |
| k: v for k, v in kwargs.items() if k != "raise_exception" | |
| } | |
| result = result and super(FetchmailServer, this).fetch_mail( | |
| **super_kwargs | |
| ) | |
| # Forward kwargs as-is so supported parent implementations | |
| # honor the caller's raise_exception value. Fall back for | |
| # older versions that don't accept that keyword. | |
| try: | |
| result = result and super(FetchmailServer, this).fetch_mail( | |
| **kwargs | |
| ) | |
| except TypeError as err: | |
| if ( | |
| "raise_exception" not in kwargs | |
| or "raise_exception" not in str(err) | |
| or "unexpected keyword" not in str(err) | |
| ): | |
| raise | |
| super_kwargs = { | |
| k: v for k, v in kwargs.items() if k != "raise_exception" | |
| } | |
| result = result and super(FetchmailServer, this).fetch_mail( | |
| **super_kwargs | |
| ) |
|
I am assuming this is an 18.0 issue because the reported traceback explicitly comes from the Odoo 18.0 code path. In 18.0, core self.search([("state", "=", "done"), ("server_type", "!=", "local")]).fetch_mail(
raise_exception=False
)The current 18.0 implementation of That said, your concern is valid: this should not be a cross-version compatibility workaround if the target is only 18.0. I will simplify the PR so it only aligns this addon override with the Odoo 18.0 core signature and forwards So the intended assumption is:
|
262140d to
a968894
Compare
|
Updated the branch to match the assumption above. Current scope is now only 18.0 signature alignment:
Local check run: |
This ensures the fix for OCA#3509 is properly tested by verifying that raise_exception is correctly passed to the parent fetch_mail method and filtered from kwargs before passing to super().
a968894 to
b11f809
Compare
|
Adjusted the new regression test after the CI failure. The previous assertion was wrong: in Odoo core, Local check run again: |
|
@fsmw I really do not think this PR solves a real problem. If any code calls fetchmail with the raise_exception argument, it is already transparently passed to the super() fetchmail. Your change would make the code less resilient for any future parameter changes without offering any benefit that I can see. |
Summary
In Odoo 18,
fetchmail.server._fetch_mails()callsfetch_mail(raise_exception=False). This module overrodefetch_mail()with**kwargs, but the Odoo 18 parent method now has an explicitraise_exceptionparameter.Fix
Update the override signature to
fetch_mail(self, raise_exception=True)and pass that argument through to the parentfetch_mail()call. This keeps the module aligned with the Odoo 18 API and prevents the scheduled fetchmail job from failing with an unexpected keyword argument error.A regression test covers calling
fetch_mail(raise_exception=False).Closes #3509