Skip to content

[FIX] fetchmail_attach_from_folder: handle raise_exception in fetch_mail for Odoo 18#3601

Open
fsmw wants to merge 2 commits intoOCA:18.0from
fsmw:fix/3509-raise-exception
Open

[FIX] fetchmail_attach_from_folder: handle raise_exception in fetch_mail for Odoo 18#3601
fsmw wants to merge 2 commits intoOCA:18.0from
fsmw:fix/3509-raise-exception

Conversation

@fsmw
Copy link
Copy Markdown

@fsmw fsmw commented Apr 19, 2026

Summary

In Odoo 18, the base fetchmail.server.fetch_mail() method was updated to accept a raise_exception parameter. However, when calling super().fetch_mail(**kwargs) from this module, the raise_exception parameter was being passed even though the base Odoo 17 model doesn't support it, causing a TypeError.

Fix

Filter out raise_exception from kwargs before passing to the parent fetch_mail() method. This ensures compatibility with both Odoo 17 (which doesn't have this parameter) while working correctly with Odoo 18.

Closes #3509

…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
Copilot AI review requested due to automatic review settings April 19, 2026 02:22
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hi @NL66278,
some modules you are maintaining are being modified, check this out!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_exception out of kwargs before calling the parent fetch_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.

Comment on lines +78 to +85
# 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
)
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
# 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
)

Copilot uses AI. Check for mistakes.
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().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:fetchmail_attach_from_folder Module fetchmail_attach_from_folder series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FetchmailServer.fetch_mail() got an unexpected keyword argument 'raise_exception'

3 participants