From 4ebb2452ae06bc4b238e329331bf05738c098de3 Mon Sep 17 00:00:00 2001 From: Sylvain GARANCHER Date: Tue, 6 Feb 2018 16:26:27 +0100 Subject: [PATCH] [FIX] Get attributes on the class instead of recordsets Even if the recordset is empty, this is still an instance of the class, so the @property methods are called. As this type of method is usually run on a single record, they need self.ensure_one(), which crashes when evaluated on a recordset, preventing the server to start when queue_job is installed. Getting the attributes on the class itself instead of using an empty recordset avoids evaluating property methods. This reverts commit 49d8f37b856dc2159ea4cc6e8c0cf113efd6f5a9. --- queue_job/models/base.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/queue_job/models/base.py b/queue_job/models/base.py index 5ded5c66e..a966c3ce6 100644 --- a/queue_job/models/base.py +++ b/queue_job/models/base.py @@ -16,18 +16,11 @@ class Base(models.AbstractModel): def _register_hook(self): """ register marked jobs """ super(Base, self)._register_hook() - job_methods = set() - for attr_name in dir(self): - # _cache on models is a lazy_property which raises an - # AssertionError when called on a empty model, just skip it. - if attr_name == '_cache': - continue - try: - attr = getattr(self, attr_name) - except AttributeError: - continue - if inspect.ismethod(attr) and getattr(attr, 'delayable', None): - job_methods.add(attr) + job_methods = [ + method for __, method + in inspect.getmembers(self.__class__, predicate=inspect.ismethod) + if getattr(method, 'delayable', None) + ] for job_method in job_methods: self.env['queue.job.function']._register_job(job_method)