Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 296
agconti Avatar asked Dec 28 '25 10:12

agconti


1 Answers

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).

like image 113
Martijn Pieters Avatar answered Dec 31 '25 00:12

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!