Reputation: 6555
I'm getting the following message, this use to work before. I have removed the .delay function below just to generate the message as this is a task but normally it looks like ProcessRequests.delay.(batch)
object._new_() takes no parameters
if request.method == 'POST':
batches = Batch.objects.for_user_pending(request.user)
for batch in batches:
ProcessRequests(batch) #ProcessRequests.delay is normally used here
batch.complete_update()
Task:
class ProcessRequests(Task):
name = "Request to Process"
max_retries = 1
default_retry_delay = 3
def run(self, batch):
for e in Contact.objects.filter(contact_owner=batch.user, group=batch.group):
msg = Message.objects.create(
recipient_number=e.mobile,
content=batch.content,
sender=e.contact_owner,
billee=batch.user,
sender_name=batch.sender_name
)
gateway = Gateway.objects.get(pk=2)
msg.send(gateway)
Full error:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/sms/process
Django Version: 1.5.1
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.humanize',
'south',
'sms',
'debug_toolbar')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'async_messages.middleware.AsyncMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/Users/user/Documents/workspace/s/django-env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/user/Documents/workspace/s/django-env/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
25. return view_func(request, *args, **kwargs)
File "/Users/user/Documents/workspace/s/sms/views.py" in process_all
214. ProcessRequests(batch)
Exception Type: TypeError at /sms/process
Exception Value: object.__new__() takes no parameters
Upvotes: 1
Views: 981
Reputation: 41940
It looks like you're trying to instantiate the ProcessRequests
class with parameters, but that class doesn't have a constructor which takes parameters, hence the error.
I think you just need to change...
ProcessRequests(batch)
...to...
ProcessRequests().run(batch)
...but whether it will do what you want depends on the definition of the Task
class.
Upvotes: 2