mardi 29 avril 2014

Django - céleri : Integreityerror pour une tâche de specifc - Stack Overflow


i'm using the Celery in a Django project for number of tasks .. T1,T2, T3 etc...


for a specific task say T1 i'm facing this issue, other tasks (T2, T3) working fine.


exception stacktrace


Task activity.tasks.action_create[3cf5dddc-5aa3-4f28-9849-8c0ee4e9e39d] raised unexpected: IntegrityError('actstream_action.project_id may not be NULL',)
Traceback (most recent call last):
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/celery/app/trace.py", line 238, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/celery/app/trace.py", line 416, in __protected_call__
return self.run(*args, **kwargs)
File "/home/naveen/WIP/delight/activity/tasks.py", line 21, in action_create
activity_handler(instance, verb)
File "/home/naveen/WIP/delight/activity/actions.py", line 129, in activity_handler
note=_get_note(instance))
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/actstream/actions.py", line 111, in action_handler
newaction.save()
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/base.py", line 546, in save
force_update=force_update, update_fields=update_fields)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/base.py", line 650, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/manager.py", line 215, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/query.py", line 1673, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 937, in execute_sql
cursor.execute(sql, params)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/backends/util.py", line 41, in execute
return self.cursor.execute(sql, params)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 364, in execute
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 362, in execute
return Database.Cursor.execute(self, query, params)
IntegrityError: actstream_action.project_id may not be NULL

this is the model :


class Action(models.Model):

actor_content_type = models.ForeignKey(ContentType, related_name='actor')
actor_object_id = models.CharField(max_length=255)
actor = generic.GenericForeignKey('actor_content_type', 'actor_object_id')

# Using project.Project to avoud circular dependency
project = models.ForeignKey('project.Project')
version = models.ForeignKey('project.ReleaseVersion')
note = models.ForeignKey('project.ReleaseNote', null=True)

verb = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)

target_content_type = models.ForeignKey(
ContentType, related_name='target', blank=True, null=True)
target_object_id = models.CharField(max_length=255, blank=True, null=True)
target = generic.GenericForeignKey(
'target_content_type', 'target_object_id')

action_object_content_type = models.ForeignKey(
ContentType, related_name='action_object', blank=True, null=True)
action_object_object_id = models.CharField(
max_length=255, blank=True, null=True)
action_object = generic.GenericForeignKey(
'action_object_content_type', 'action_object_object_id')

timestamp = models.DateTimeField(default=now)

public = models.BooleanField(default=True)

objects = actstream_settings.get_action_manager()

Task T1: create a Action object


def action_create(instance, created):
Action(actor, verb=verb, action_object=instance, target=_get_target(instance),
project=_get_project(instance), version=_get_version(instance),
note=_get_note(instance))

Now ...


indivaully when running task from python shell it is runing fine , creating the Action object successfully like :




action_create(some_instance, True)




But ...




from celery import chain chain(action_create.s(some_instance, True)).apply_async()




Ii throws That IntegretiError, when i inspect the celery console , the debug information saying that :


[2014-03-15 07:19:41,035: DEBUG/Worker-3] (0.000) INSERT INTO "actstream_action" ("actor_content_type_id", "actor_object_id", "verb", "description", "target_content_type_id", "target_object_id", "action_object_content_type_id", "action_object_object_id", "timestamp", "public") VALUES (3, 1, comment_created, None, 17, 1, 19, 2, 2014-03-15 07:19:41.032665, True); args=[3, u'1', u'comment_created', None, 17, u'1', 19, u'2', u'2014-03-15 07:19:41.032665', True]

Action table does not have any project_id field, What the F**k !!!


I'm a bit confused why that field is missing from the table... I'm using south for migrations and ran it for that table.


What's bothering me is The task is successfully completed when ran individually , but fails when i chain it with celery ?


Any clue would be helpful.



i'm using the Celery in a Django project for number of tasks .. T1,T2, T3 etc...


for a specific task say T1 i'm facing this issue, other tasks (T2, T3) working fine.


exception stacktrace


Task activity.tasks.action_create[3cf5dddc-5aa3-4f28-9849-8c0ee4e9e39d] raised unexpected: IntegrityError('actstream_action.project_id may not be NULL',)
Traceback (most recent call last):
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/celery/app/trace.py", line 238, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/celery/app/trace.py", line 416, in __protected_call__
return self.run(*args, **kwargs)
File "/home/naveen/WIP/delight/activity/tasks.py", line 21, in action_create
activity_handler(instance, verb)
File "/home/naveen/WIP/delight/activity/actions.py", line 129, in activity_handler
note=_get_note(instance))
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/actstream/actions.py", line 111, in action_handler
newaction.save()
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/base.py", line 546, in save
force_update=force_update, update_fields=update_fields)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/base.py", line 650, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/manager.py", line 215, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/query.py", line 1673, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 937, in execute_sql
cursor.execute(sql, params)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/backends/util.py", line 41, in execute
return self.cursor.execute(sql, params)
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 364, in execute
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
File "/home/naveen/ENV/delight/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 362, in execute
return Database.Cursor.execute(self, query, params)
IntegrityError: actstream_action.project_id may not be NULL

this is the model :


class Action(models.Model):

actor_content_type = models.ForeignKey(ContentType, related_name='actor')
actor_object_id = models.CharField(max_length=255)
actor = generic.GenericForeignKey('actor_content_type', 'actor_object_id')

# Using project.Project to avoud circular dependency
project = models.ForeignKey('project.Project')
version = models.ForeignKey('project.ReleaseVersion')
note = models.ForeignKey('project.ReleaseNote', null=True)

verb = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)

target_content_type = models.ForeignKey(
ContentType, related_name='target', blank=True, null=True)
target_object_id = models.CharField(max_length=255, blank=True, null=True)
target = generic.GenericForeignKey(
'target_content_type', 'target_object_id')

action_object_content_type = models.ForeignKey(
ContentType, related_name='action_object', blank=True, null=True)
action_object_object_id = models.CharField(
max_length=255, blank=True, null=True)
action_object = generic.GenericForeignKey(
'action_object_content_type', 'action_object_object_id')

timestamp = models.DateTimeField(default=now)

public = models.BooleanField(default=True)

objects = actstream_settings.get_action_manager()

Task T1: create a Action object


def action_create(instance, created):
Action(actor, verb=verb, action_object=instance, target=_get_target(instance),
project=_get_project(instance), version=_get_version(instance),
note=_get_note(instance))

Now ...


indivaully when running task from python shell it is runing fine , creating the Action object successfully like :




action_create(some_instance, True)




But ...




from celery import chain chain(action_create.s(some_instance, True)).apply_async()




Ii throws That IntegretiError, when i inspect the celery console , the debug information saying that :


[2014-03-15 07:19:41,035: DEBUG/Worker-3] (0.000) INSERT INTO "actstream_action" ("actor_content_type_id", "actor_object_id", "verb", "description", "target_content_type_id", "target_object_id", "action_object_content_type_id", "action_object_object_id", "timestamp", "public") VALUES (3, 1, comment_created, None, 17, 1, 19, 2, 2014-03-15 07:19:41.032665, True); args=[3, u'1', u'comment_created', None, 17, u'1', 19, u'2', u'2014-03-15 07:19:41.032665', True]

Action table does not have any project_id field, What the F**k !!!


I'm a bit confused why that field is missing from the table... I'm using south for migrations and ran it for that table.


What's bothering me is The task is successfully completed when ran individually , but fails when i chain it with celery ?


Any clue would be helpful.


0 commentaires:

Enregistrer un commentaire