Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

methods as tasks fail with CELERY_ALWAYS_EAGER=True #1478

Closed
Karmak23 opened this issue Jul 18, 2013 · 4 comments
Closed

methods as tasks fail with CELERY_ALWAYS_EAGER=True #1478

Karmak23 opened this issue Jul 18, 2013 · 4 comments

Comments

@Karmak23
Copy link

Hi,

I've got this stacktrace when I run tests of my webapp:

Traceback (most recent call last):
  File "/Users/olive/sources/1flow/oneflow/core/tests/test_models.py", line 219, in setUp
    url='http://test.com/test1').save()
  File "/Users/olive/.virtualenvs/1flow/lib/python2.7/site-packages/mongoengine/document.py", line 298, in save
    signals.post_save.send(self.__class__, document=self, created=created)
  File "/Users/olive/.virtualenvs/1flow/lib/python2.7/site-packages/blinker/base.py", line 267, in send
    for receiver in self.receivers_for(sender)]
  File "/Users/olive/sources/1flow/oneflow/core/models/nonrel.py", line 1546, in signal_post_save_handler
    document.post_save_task.delay()
  File "/Users/olive/.virtualenvs/1flow/lib/python2.7/site-packages/celery/app/task.py", line 358, in delay
    return self.apply_async(args, kwargs)
  File "/Users/olive/.virtualenvs/1flow/lib/python2.7/site-packages/celery/app/task.py", line 463, in apply_async
    link=link, link_error=link_error, **options)
  File "/Users/olive/.virtualenvs/1flow/lib/python2.7/site-packages/celery/app/task.py", line 638, in apply
    request=request, propagate=throw)
  File "/Users/olive/.virtualenvs/1flow/lib/python2.7/site-packages/celery/task/trace.py", line 331, in eager_trace_task
    uuid, args, kwargs, request)
  File "/Users/olive/.virtualenvs/1flow/lib/python2.7/site-packages/celery/task/trace.py", line 233, in trace_task
    R = retval = fun(*args, **kwargs)
TypeError: post_save_task() takes exactly 1 argument (2 given)

In my tests, I have:

@override_settings(STATICFILES_STORAGE=
                   'pipeline.storage.NonPackagingPipelineStorage',
                   CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
                   CELERY_ALWAYS_EAGER=True,
                   BROKER_BACKEND='memory',)
class ArticleDuplicateTest(TestCase):


    def setUp(self):

        Article.drop_collection()

        self.article1 = Article(title='test1',
                                url='http://test.com/test1').save()

The crash doesn't happen in "normal" conditions: if I remove the settings override, the post_save_task() runs without problem, but not in the right database (obviously because of production broker, different mongoengine connection, etc).

The task-related code:

from mongoengine import Document, ValidationError
from celery.contrib.methods import task as celery_task_method

class Article(Document):

    #[…]

    @classmethod
    def signal_post_save_handler(cls, sender, document, **kwargs):
        if kwargs.get('created', False):
            document.post_save_task.delay()

    @celery_task_method(name='Article.post_save', queue='high')
    def post_save_task(self):

        self.slug = slugify(self.title)
        self.save()

Any hint/advise ?

@rafaponieman
Copy link

Reporting occurrence of the same issue. On a normal request, running celery with CELERY_ALWAYS_EAGER=False it works perfectly, however, when I run tasks in tests (with CELERY_ALWAYS_EAGER=True), it passes the class (method's owner) as a parameter to the method apart from passing it to the self argument (it adds an extra arg).

ask added a commit that referenced this issue Oct 9, 2013
@ask ask closed this as completed in 0ffbaaf Oct 9, 2013
@Karmak23
Copy link
Author

Karmak23 commented Oct 9, 2013

I won't be able to test because now all my tasks are regular tasks, for production-ready reasons I needed to make tests work. Next time I need to develop tasks i will retry using tasks as methods :-)

But that's very good news !! Thanks a lot for this patch.

@rafaponieman
Copy link

Same case here, we resorted to a normal function task that calls the class method, this way it works fine. Next time we'll try it. Thanks a lot!

@ask
Copy link
Contributor

ask commented Oct 11, 2013

The task methods are very experimental so I would expect you to find more bugs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants