2

I'm trying to enqueue a basic job in redis using django_rq, a python library for queueing jobs and processing them in the background with workers, but the simple call throws a:

AttributeError: 'dict' object has no attribute '__module__' 

I've traced down the issue to this line in the rq library:

 if not isinstance(f, string_types) and f.__module__ == '__main__':
            raise ValueError('Functions from the __main__ module cannot be processed '
                             'by workers.')

I'm passing a function in as f so I dont understand how it can throw an attribute error on a dict. Any ideas on whats going wrong?

Stack Trace:

  File "/Users/admin/dev/feedme-web/feedme/api/views.py", line 133, in post
    parameter_dict = {
  File "/Users/admin/dev/feedme-web/feedme-env/lib/python2.7/site-packages/django_rq/queues.py", line 162, in enqueue
    return get_queue().enqueue(func, *args, **kwargs)
  File "/Users/admin/dev/feedme-web/feedme-env/lib/python2.7/site-packages/rq/queue.py", line 159, in enqueue
    if not isinstance(f, string_types) and f.__module__ == '__main__':

Function being enqueued:

def create_order_ordrin(user, card_primary_key, address_primary_key):
    parameter_dict = {
      """... pararmeters for call here ..."""
    }
    ordrin = initialize_ordrin()
    return ordrin.order_user(**parameter_dict)

* note the values user, card_primary_key, and address_primary_key are not being used yet

2
  • 1
    Are you sure you didn't accidentally call the function and are passing in the dictionary returned by the function? Commented Mar 12, 2014 at 17:12
  • @MartijnPieters you're right, thats exactly whats happening. but how can I enqueue the function with the proper parameters with out calling it? Commented Mar 12, 2014 at 17:16

1 Answer 1

9

You are calling the function and passing in the result of the function call to the queue.

Register the function without calling it, and include the arguments to be passed when it is to be called:

django_rq.enqueue(create_order_ordrin, foo, bar=baz)

and it'll be called as create_order_ordrin(foo, bar=baz).

Sign up to request clarification or add additional context in comments.

1 Comment

your a champ; this works great. I've read through that part of the docs many times, but I kept using django_rq.enqueue(create_order_ordrin(), foo, bar=baz). thanks for setting me straight on those ().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.