ask/celery — Issue #611: Getting TypeError when retrying a task in v2.5
Author: lsemel
Created: 2012-02-16 19:56:40+00:00
State: open

This is the general structure of my task:

@task(ignore_result=False, soft_time_limit=30, max_retries=10)
def my_task(id, retry_countdown=None, options=None):
"""retry_countdown lets the caller specify a custom amount of time before retrying"""
try:
SomeModel = SomeModel.objects.get(pk=id)
except SomeModel.DoesNotExist:
return
try:
options = options or {}
results = do_something(options)
return {...stuff...}
except SomeModels.SomeModelException as exc:
if retry_countdown:
return my_task.retry(exc=exc, countdown=retry_countdown)

In v2.5 whenever it fails and tries to retry, I get a TypeError in the log:

2012-02-16 14:21:54,187: ERROR/MainProcess] Task muypp.tasks.my_task[2e82aab5-bbdb-4252-9793-37bf2457795f] raised exception: TypeError('__init__() takes exactly 3 arguments (2 given)',)
Traceback (most recent call last):
File "/opt/virtualenvs/myapp/src/celery/celery/execute/trace.py", line 158, in trace_task
R = I.handle_error_state(task, eager=eager)
File "/opt/virtualenvs/myapp/src/celery/celery/execute/trace.py", line 67, in handle_error_state
}[self.state](task, store_errors=store_errors)
File "/opt/virtualenvs/myapp/src/celery/celery/execute/trace.py", line 79, in handle_retry
task.backend.mark_as_retry(req.id, orig_exc, self.strtb)
File "/opt/virtualenvs/myapp/src/celery/celery/backends/base.py", line 102, in mark_as_retry
traceback=traceback)
File "/opt/virtualenvs/myapp/src/celery/celery/backends/base.py", line 229, in store_result
return self._store_result(task_id, result, status, traceback, **kwargs)
File "/opt/virtualenvs/myapp/src/django-celery/djcelery/backends/database.py", line 27, in _store_result
traceback=traceback)
File "/opt/virtualenvs/myapp/src/django-celery/djcelery/managers.py", line 41, in _inner
return fun(*args, **kwargs)
File "/opt/virtualenvs/myapp/src/django-celery/djcelery/managers.py", line 169, in store_result
"traceback": traceback})
File "/opt/virtualenvs/myapp/src/django-celery/djcelery/managers.py", line 83, in update_or_create
return self.get_query_set().update_or_create(**kwargs)
File "/opt/virtualenvs/myapp/src/django-celery/djcelery/managers.py", line 72, in update_or_create
update_model_with_dict(obj, fields)
File "/opt/virtualenvs/myapp/src/django-celery/djcelery/managers.py", line 60, in update_model_with_dict
obj.save()
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/base.py", line 526, in save_base
rows = manager.using(using).filter(pk=pk_val)._update(values)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/query.py", line 491, in _update
return query.get_compiler(self.db).execute_sql(None)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 869, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 725, in execute_sql
sql, params = self.as_sql()
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 834, in as_sql
val = field.get_db_prep_save(val, connection=self.connection)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/fields/subclassing.py", line 28, in inner
return func(*args, **kwargs)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/fields/subclassing.py", line 28, in inner
return func(*args, **kwargs)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/fields/__init__.py", line 276, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/django/db/models/fields/subclassing.py", line 53, in inner
return func(*args, **kwargs)
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/picklefield/fields.py", line 129, in get_db_prep_value
value = force_unicode(dbsafe_encode(value, self.compress, self.protocol))
File "/opt/virtualenvs/myapp/lib/python2.6/site-packages/picklefield/fields.py", line 39, in dbsafe_encode
value = b64encode(dumps(deepcopy(value), pickle_protocol))
File "/usr/lib/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py", line 322, in _reconstruct
args = deepcopy(args, memo)
File "/usr/lib/python2.6/copy.py", line 162, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.6/copy.py", line 235, in _deepcopy_tuple
y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py", line 323, in _reconstruct
y = callable(*args)
TypeError: __init__() takes exactly 3 arguments (2 given)