0

Tring out Django Celery for the first time, new to Django and Celery.

Below is what I have so far trying I get the following error...

RuntimeError at /contacts/upload maximum recursion depth exceeded

I'm using SQS and the message broker.

settings.py

# Celery

import djcelery
djcelery.setup_loader()

INSTALLED_APPS += (
    'south',
    'userena',
    'social_auth',
    'djcelery',


)

BROKER_TRANSPORT = 'sqs'
BROKER_TRANSPORT_OPTIONS = {
    'region': 'eu-west-1',
    }
BROKER_USER = 'xyz'
BROKER_PASSWORD = 'zyx'

tasks.py

@task
def upload(request, **kwargs):
    file = request.FILES['file']
    ContactCSVModel.import_from_file(file)
    return True

view.py

@login_required
def upload(request):

            result = upload(request)
            if result:
                messages.add_message(request, messages.SUCCESS, 'Items have been added to the database.')
        else:

         etc

Can someone please help me understand what I'm doing wrong here. Thank you.

2 Answers 2

2

Your task and your view are called exactly the same thing.

So when you do this:

result = upload(request)

You're not calling your task, as I think you expect, you're calling your view function again. And again. And again. And again.

Try changing your view def to:

def upload_file(request):

The should fix the problem.

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

Comments

1

Rename your task:

@task
def upload_task():
    ...

def upload(request):
    result = upload_task(request)

If view and task has the same name, inside upload view, when upload called, upload is the upload view itself.

Comments

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.