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 into
OCA: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 into
OCA:18.0from
fsmw:fix/3509-raise-exception

Conversation

@fsmw
Copy link
Copy Markdown

@fsmw fsmw commented Apr 19, 2026

Summary

In Odoo 18, fetchmail.server._fetch_mails() calls fetch_mail(raise_exception=False). This module overrode fetch_mail() with **kwargs, but the Odoo 18 parent method now has an explicit raise_exception parameter.

Fix

Update the override signature to fetch_mail(self, raise_exception=True) and pass that argument through to the parent fetch_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

…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.
Copy link
Copy Markdown
Contributor

@NL66278 NL66278 left a comment

Choose a reason for hiding this comment

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

@fsmw Why should we change the 18.0 branch for a problem that might only occur in 17.0?

@fsmw
Copy link
Copy Markdown
Author

fsmw commented Apr 30, 2026

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 mail.models.fetchmail.FetchmailServer._fetch_mails() calls:

self.search([("state", "=", "done"), ("server_type", "!=", "local")]).fetch_mail(
    raise_exception=False
)

The current 18.0 implementation of fetchmail_attach_from_folder overrides fetch_mail() without the same explicit signature, so the cron call can fail when that override is in the method resolution path.

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 raise_exception to super(), instead of trying to handle older parent signatures.

So the intended assumption is:

  • target branch: OCA 18.0
  • failing caller: Odoo 18.0 core _fetch_mails()
  • fix scope: make this addon’s 18.0 override signature match the 18.0 core method
  • not trying to fix a 17.0-only issue in 18.0

@fsmw fsmw force-pushed the fix/3509-raise-exception branch from 262140d to a968894 Compare April 30, 2026 20:05
@fsmw
Copy link
Copy Markdown
Author

fsmw commented Apr 30, 2026

Updated the branch to match the assumption above.

Current scope is now only 18.0 signature alignment:

  • fetch_mail(self, raise_exception=True) mirrors Odoo 18.0 core
  • forwards raise_exception to super()
  • removed the older-parent compatibility workaround
  • added a focused regression test for calling the override with raise_exception=False

Local check run: pre-commit run --files fetchmail_attach_from_folder/models/fetchmail_server.py fetchmail_attach_from_folder/tests/test_fetchmail_server.py fetchmail_attach_from_folder/tests/__init__.py.

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().
@fsmw fsmw force-pushed the fix/3509-raise-exception branch from a968894 to b11f809 Compare April 30, 2026 21:08
@fsmw
Copy link
Copy Markdown
Author

fsmw commented Apr 30, 2026

Adjusted the new regression test after the CI failure.

The previous assertion was wrong: in Odoo core, fetch_mail(raise_exception=False) swallows the connection failure and still returns True. The regression being covered here is only that the 18.0 override accepts the raise_exception=False keyword and returns normally instead of raising TypeError.

Local check run again: pre-commit run --files fetchmail_attach_from_folder/tests/test_fetchmail_server.py fetchmail_attach_from_folder/models/fetchmail_server.py fetchmail_attach_from_folder/tests/__init__.py.

@NL66278
Copy link
Copy Markdown
Contributor

NL66278 commented Apr 30, 2026

@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.

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'

4 participants