Skip to content

[18.0][FIX] queue_job: keep requested method name - #998

Merged
OCA-git-bot merged 2 commits into
OCA:18.0from
akarazhev:18.0-fix-queue_job-method-name
Oct 20, 2026
Merged

OCA-git-bot merged 2 commits into
OCA:18.0from
akarazhev:18.0-fix-queue_job-method-name

Conversation

@akarazhev

Copy link
Copy Markdown

Fixes #996.

A job was recorded by the __name__ of the function found under the requested
attribute, not by the attribute name. When a module installs a replacement
under another name — auditlog puts write_full and unlink_full into the
write and unlink slots — the job stores unlink_full and fails with
AttributeError as soon as it resolves that name on the recordset.

The name is lost in four places, so this PR keeps it from the moment it is
looked up:

  • Delayable.__getattr__ stores the requested name next to the method;
    split(), the description fallback and repr use it instead of __name__;
  • Job.__init__ takes an optional method_name, defaulting to
    func.__name__ so existing callers are unchanged;
  • Job._load_from_db_record passes the stored method_name, otherwise a job
    loaded from the database would pick up __name__ again;
  • Job.description falls back to method_name.

Tests cover delayable().delay(), with_delay() and split(), and check that
the stored and the reloaded job both carry the requested name. Without the fix
they fail with the AttributeError from the issue; with it, queue_job and
test_queue_job pass locally on Odoo 18 with PostgreSQL 16 (231 tests).

The same pattern exists in _patch_job_auto_delay
(models/base.py, auto_delay_wrapper.origin.__name__). I left it out to keep
this PR focused; happy to add it here or in a follow-up.

Related: #940 lets the runner skip a job whose method no longer exists.
This PR is complementary — it keeps the right name from being lost in the
first place. Both touch Job._load_from_db_record a few lines apart; I will
rebase if #940 lands first.

@oca-cla-bot

oca-cla-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

@florentx florentx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LG, thanks.

Comment thread queue_job/delay.py Outdated
@@ -485,7 +487,7 @@ def _tail(self):
def __repr__(self):
return (
f"Delayable({self.recordset}."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If default value is "" instead of None (line 475 above), then it can be:

Suggested change
f"Delayable({self.recordset}."
f"Delayable({self.recordset}.{self._job_method_name}"
f"({self._job_args}, {self._job_kwargs}))"
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks — applied and folded into the queue_job commit.

queue_job recorded a delayed method by the __name__ of the function found
under the requested attribute. A module that installs a replacement under
another name (auditlog: write_full, unlink_full) made the job store that
name and fail with AttributeError when resolving it. Keep the looked-up
name in Delayable, pass it to Job, and reuse the stored name on load.

Fixes #996
Delay a method replaced under another __name__ through delayable(),
with_delay() and split(), and check the stored and reloaded job keep
the requested name.
@akarazhev
akarazhev force-pushed the 18.0-fix-queue_job-method-name branch from 7f7306e to c3e5a07 Compare September 24, 2026 13:45
@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@simahawk

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 18.0-ocabot-merge-pr-998-by-simahawk-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 59b1a3e into OCA:18.0 Oct 20, 2026
8 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at b1c40fe. Thanks a lot for contributing to OCA. ❤️

akarazhev added a commit to akarazhev/akarazhev that referenced this pull request Oct 21, 2026
akarazhev added a commit to akarazhev/minihub-site that referenced this pull request Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delaying unlink or write on a model whose method was replaced raises AttributeError at enqueue time

5 participants