Skip to content

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

Description

@JsickOpenfellas

Module

queue_job (18.0.1.3.0).

Describe the bug

A delayed call (delayable() and with_delay()) is recorded by the __name__ of the function that the
attribute lookup happened to return, not by the name that was looked up

 recordset_method = getattr(self.recordset, name)
self._job_method = recordset_method 

This leads to:

  File "queue_job/job.py", in _store_values
      "name": self.description,
  File "queue_job/job.py", in description
      elif self.func.__doc__:
  File "queue_job/job.py", in func
      return getattr(recordset, self.method_name)
  AttributeError: 'res.partner' object has no attribute 'unlink_renamed'

To Reproduce

Affected Versions:
Occured on 18.0 but code is unchanged on newer versions.

  cls = type(env["res.partner"])
  original = cls.unlink

  def unlink_renamed(self):
      return unlink_renamed.origin(self)

  unlink_renamed.origin = original
  cls.unlink = unlink_renamed

  partner = env["res.partner"].create({"name": "test"})
  partner.delayable().unlink().delay()

Expected behavior
The job records the method under the name it was requested with, and resolves
that name again, independent of what the attribute currently points at.

Additional context
Where this shows up in practice

auditlog (https://github.com/OCA/server-tools) installs its replacements as write_full and unlink_full into
the write and unlink slots, so any delayed write or unlink on an
audited model fails this way.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions