django-celery icon indicating copy to clipboard operation
django-celery copied to clipboard

IntegrityError('null value in column "task_id" violates not-null constraint

Open MikeHibbert opened this issue 9 years ago • 2 comments

Hi

I'm trying to update the state of my current_task but receiving the following error:

Traceback (most recent call last):
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/mike/Documents/python/hitter/hitter/analysis/tasks.py", line 81, in import_new_user
    get_following_for_new_account(crnt_task, user_id, account.id)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/local.py", line 167, in <lambda>
    __call__ = lambda x, *a, **kw: x._get_current_object()(*a, **kw)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/app/trace.py", line 439, in __protected_call__
    return orig(self, *args, **kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/app/task.py", line 420, in __call__
    return self.run(*args, **kwargs)
  File "/home/mike/Documents/python/hitter/hitter/analysis/tasks.py", line 265, in get_following_for_new_account
    update_following_status(crnt_task, account, following, following_processed, twitter_user)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/local.py", line 167, in <lambda>
    __call__ = lambda x, *a, **kw: x._get_current_object()(*a, **kw)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/app/trace.py", line 439, in __protected_call__
    return orig(self, *args, **kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/app/task.py", line 420, in __call__
    return self.run(*args, **kwargs)
  File "/home/mike/Documents/python/hitter/hitter/analysis/tasks.py", line 382, in update_following_status
    'total': 333})
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/app/task.py", line 802, in update_state
    self.backend.store_result(task_id, meta, state)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/celery/backends/base.py", line 256, in store_result
    request=request, **kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/djcelery/backends/database.py", line 29, in _store_result
    traceback=traceback, children=self.current_task_children(request),
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/djcelery/managers.py", line 42, in _inner
    return fun(*args, **kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/djcelery/managers.py", line 181, in store_result
    'meta': {'children': children}})
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/djcelery/managers.py", line 87, in update_or_create
    return get_queryset(self).update_or_create(**kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/djcelery/managers.py", line 70, in update_or_create
    obj, created = self.get_or_create(**kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/query.py", line 424, in get_or_create
    return self._create_object_from_params(lookup, params)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/query.py", line 465, in _create_object_from_params
    six.reraise(*exc_info)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/query.py", line 457, in _create_object_from_params
    obj.save(force_insert=True, using=self.db)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/base.py", line 589, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/base.py", line 617, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/base.py", line 698, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/base.py", line 731, in _do_insert
    using=using, raw=raw)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/mike/Documents/python/hitter/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
IntegrityError: null value in column "task_id" violates not-null constraint
DETAIL:  Failing row contains (27, null, TWITTER_FOLLWING_IMPORT_PROCESSED, gAJ9cQEoVQdjdXJyZW50cQJLAlUFdG90YWxxA01NAXUu, 2015-07-05 17:10:57.238296+00, null, f, eJxrYKotZIzgYGBgSM7IzEkpSs0rZIotZC7WAwBWuwcA).

The line generating the error is just the call to current_task.update_state;

current_task.update_state(state="TWITTER_FOLLOWING_IMPORT_PROCESSED",
                                            meta={'current': following_processed,
                                                       'total': twitter_user.friends_count})

Whats causing this to happen?

Thanks in advance!

Mike

MikeHibbert avatar Jul 05 '15 17:07 MikeHibbert

@MikeHibbert which celery / django-celery versions are you using?

czpython avatar Aug 15 '15 18:08 czpython

FYI: I got this error because I forgot to use .delay() in the function! So instead of using celery_function.delay(arguments) I used celery_function(arguments)..

LouisdeBruijn avatar May 08 '20 13:05 LouisdeBruijn