Skip to content

Commit

Permalink
Prevent lazy_property error on jobs registration
Browse files Browse the repository at this point in the history
The _cache lazy_property fail on getattr, skip it. Under the hood,
inspect.getmembers() does exactly the same thing with dir and getattr.
  • Loading branch information
guewen authored and lepistone committed Oct 3, 2017
1 parent 2b78d83 commit 49d8f37
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions queue_job/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ class Base(models.AbstractModel):
def _register_hook(self):
""" register marked jobs """
super(Base, self)._register_hook()
job_methods = [method for __, method
in inspect.getmembers(self, predicate=inspect.ismethod)
if getattr(method, 'delayable', None)]
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)
for job_method in job_methods:
self.env['queue.job.function']._register_job(job_method)
# add_to_job_registry(job_methods)

@api.multi
def with_delay(self, priority=None, eta=None,
Expand Down

0 comments on commit 49d8f37

Please sign in to comment.