django-rq: AttributeError: 'module' object has no attribute

I am trying to create a background job with RQ:

import django_rq                                                         


    def _send_password_reset_email_async(email):                             
        print(email)                                                         

    # Django admin action to send reset password emails                                                                 
    def send_password_reset_email(modeladmin, request, queryset):            
        for user in queryset:                                                
            django_rq.enqueue(_send_password_reset_email_async, user.email)  
    send_password_reset_email.short_description = 'Send password reset email'

I keep getting this error:

Traceback (most recent call last):
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/rq/worker.py", line 568, in perform_job
    rv = job.perform()
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/rq/job.py", line 

495, in perform
    self._result = self.func(*self.args, **self.kwargs)
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/rq/job.py", line 206, in func
    return import_attribute(self.func_name)
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/rq/utils.py", line 151, in import_attribute
    return getattr(module, attribute)
AttributeError: 'module' object has no attribute '_send_password_reset_email_async

I also posted it to SO earlier http://stackoverflow.com/questions/32733934/rq-attributeerror-module-object-has-no-attribute

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 19

Most upvoted comments

Adding a comment as I too ran into this error:

Rqworker does not dynamically reload when you change your code, but the Django dev webserver does So if you add/modify a task & immediately call it, you may run into this error as the new code (your web code) tries to call the old code (the RQ task).

Stop/restart rqworker and you’re ok.

_send_password_reset_email_async is local function inside function. Declare it on module level @krlx

Hi I’m having the same issue with this.

I’m trying to execute some rq tasks in views following below.

        # Send email notification to internal team.
        django_rq.enqueue(
            func=task_email_send_internal_team_for_seller_sign_up,
            args=[
                user.get_full_name(),
                user.email,
                member.telephone,
                company.company_name
            ]
        )

        # Send email notification to internal team.
        django_rq.enqueue(
            func=task_email_sales_for_vendor_approvement,
            args=[member.pk]
        )

        # Send email activation to vendor.
        token = SellerTokenActivation.generate(member=member)
        activation_url = SellerTokenActivation.generate_public_url(token=token.token)
        django_rq.enqueue(
            func=task_email_token_activation_for_vendor,
            args=[
                member.companyinformation.company_name,
                email,
                activation_url,
                username,
                password,
            ]
        )

Sometimes the tasks is not executed properly in worker. Some task succeed and the rest failed. I expect those task are executed properly.

These are my rq and django-rq versions

django-rq==1.2.0
rq==0.12.0

Here is the stacktrace from django rq admin

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 793, in perform_job
    rv = job.perform()
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 599, in perform
    self._result = self._execute()
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 605, in _execute
    return self.func(*self.args, **self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 213, in func
    return import_attribute(self.func_name)
  File "/usr/local/lib/python2.7/dist-packages/rq/utils.py", line 153, in import_attribute
    return getattr(module, attribute)
AttributeError: 'module' object has no attribute 'task_email_token_activation_for_vendor'