Skip to content

Commit

Permalink
fix class task exception raising
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Jun 13, 2013
1 parent 268c224 commit 4e2c844
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions kuyruk/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ def object_to_id(f):
def inner(self, *args, **kwargs):
cls = self.cls or self.arg_class
if cls:
if not args:
try:
obj = args[0]
except IndexError:
raise InvalidCall("You must give an instance of %s as first "
"argument." % cls.__name__)

obj = args[0]
if not isinstance(obj, cls):
raise InvalidCall("%s object must have an id attribute." %
raise InvalidCall("First argument must be an instance of %s." %
cls.__name__)

args = list(args)
args[0] = args[0].id
try:
args[0] = args[0].id
except AttributeError:
raise InvalidCall("%s object must have an id attribute." %
cls.__name__)
return f(self, *args, **kwargs)
return inner

Expand Down

0 comments on commit 4e2c844

Please sign in to comment.