Tuesday, April 21, 2020

While executing a Celery Task : 'AsyncResult' object is not iterable

I am Using Celery to perform a task in the background on form submission. As soon as form is submitted during POST request, I have created a task to execute in the back ground using delay method. This task processes some click operations on some other web using selenium web driver and return two python lists after task execution. Based on list content I want to display pop up message.

When I execute the task using celery and run the Django web development server on form submit , I am getting error message: 'AsyncResult' object is not iterable".

Please suggest how to resolve this issue and proceed further.

Here is my code snippet: sample List content which obtained through selenium operations on web page is as shown below:


board_not_used_list = ['16123','14960']  board_mgr_permissions_not_present_list = [ '23456','45678']
 views.py:      --------       def conclude_key_issue_form(request, id=None):          if id:              action = 'edit'              model = get_object_or_404(ConcludeKeyIssues, pk=id)            else:              action = 'submit'              model = ConcludeKeyIssues()            message = ""                 if request.method == 'POST':                form = ConcludeKeyIssuesForm(request.POST, instance=model)                selected_model_name = request.POST.get('registered_model')                        if form.is_valid():                    new_key_issue_request = form.save(commit=False)                  new_key_issue_request.integrator_id = request.user.username                    integrator_username = new_key_issue_request.integrator_id                  integrator_password = form.cleaned_data['integrator_pwd']                    new_key_issue_request.integrator_pwd = integrator_password                    new_key_issue_request.save()                  form.save_m2m()                    created_pk = new_key_issue_request.pk                    if id is None:                      board_not_used_list,                             board_mgr_permissions_not_present_list=                                         task_check_board_availability_and_permissions.delay(created_pk)                if board_not_used_list and   board_mgr_permissions_not_present_list:                  alert_flag = True                  alert_message = "SAS Board ID's:{} in Not Used state."                  context = {'form': form, 'registered_model_data': registered_models,                                'alert': alert_flag, 'alert_message': json.dumps(alert_message)}                  return render(request, 'ConcludeKeyIssue.html', context)                elif not board_not_used_list and board_mgr_permissions_not_present_list:                  alert_flag = True                  alert_message = "You don't have Board Manager Permissions"                  context = {'form': form, 'registered_model_data': registered_models,                                 'alert': alert_flag, 'alert_message': json.dumps(alert_message)}                  return render(request, 'ConcludeKeyIssue.html', context)                return HttpResponseRedirect('/swatapp/ConcludeKeyIssueList')    else:      print("Fill Conclude Key Issues")      form = ConcludeKeyIssuesForm(instance=model)            context = {'form': form,'Message': message, 'action': action}        return render(request, 'ConcludeKeyIssue.html', context)    Tasks.py:  --------  @app.task(name="task_check_board_availability_and_permissions")  def task_check_board_availability_and_permissions(created_pk):      print("From tasks.py conclude_key_issue_through_selenium")        print("Conclude Key Issue Through Selenium")        latest_record_pk = created_pk        # Get the instances of ConcludeKeyIssues      conclude_key_issue_obj_list = ConcludeKeyIssues.objects.all()        # Get the latest created record details      get_created_record_details = ConcludeKeyIssues.objects.get(pk=latest_record_pk)        # Get the id or location value of selected from SAS URL      sas_board_ids = get_created_record_details.sas_ids        # Get SAS Board IDs in list      sas_board_ids_list = sas_board_ids.split(",")          # Input username and password      username = get_created_record_details.integrator_id      password = get_created_record_details.integrator_pwd        board_not_used_list, board_mgr_permissions_not_present_list = \          check_board_availability_and_permissions_for_all_requested_sas(sas_board_ids_list, username,                                                                          password)          return board_not_used_list, board_mgr_permissions_not_present_list        settings.py:  ------------  INSTALLED_APPS = [      'django.contrib.admin',      'django.contrib.auth',      'django.contrib.contenttypes',      'django.contrib.sessions',      'django.contrib.messages',      'django.contrib.staticfiles',      'crispy_forms',      'swatapp',      'django_celery_results',  ]  CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//'  CELERY_RESULT_BACKEND = 'django-db'

1.Please suggest how to resolve this error and proceed further.

2.How to retrieve the 2 lists [ board_not_used_list,board_mgr_permissions_not_present_list] using celery result.


Regards,

N.Dilip Kumar.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b8c7dc6d-2f5a-4963-a972-776ca84bc822%40googlegroups.com.

No comments:

Post a Comment