[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#3601
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 | |
| ) |
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().
Summary
In Odoo 18, the base
fetchmail.server.fetch_mail()method was updated to accept araise_exceptionparameter. However, when callingsuper().fetch_mail(**kwargs)from this module, theraise_exceptionparameter was being passed even though the base Odoo 17 model doesn't support it, causing aTypeError.Fix
Filter out
raise_exceptionfrom kwargs before passing to the parentfetch_mail()method. This ensures compatibility with both Odoo 17 (which doesn't have this parameter) while working correctly with Odoo 18.Closes #3509