Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'list' object has no attribute 'splitlines' when using multiple choice questions in survey #513

Closed
wilf1rst opened this issue Aug 8, 2022 · 6 comments

Comments

@wilf1rst
Copy link

wilf1rst commented Aug 8, 2022

Describe the bug
Squest throw an exception when an AWX survey have either 'multiple select' or 'multiple select multiple' type of field.

To Reproduce
Steps to reproduce the behavior:

  1. Make a survey on AWX with either 'multiple select' or 'multiple select multiple' type of field
  2. Click on the button "Order" to get a ressource that have this survey
  3. Squest throw the exception 'list' object has no attribute 'splitlines'

Expected behavior
Survey can be displayed

Errors

Request Method: | GET
-- | --
http://squest.example.com/ui/service_catalog/service/6/operation/4/request/
3.2.13
AttributeError
'list' object has no attribute 'splitlines'
/app/service_catalog/forms/utils.py, line 25, in get_choices_from_string
/usr/local/bin/python
3.10.6
['/app',  '/app/squest',  '/usr/local/lib/python3.10/site-packages/git/ext/gitdb',  '/app',  '/usr/local/bin',  '/usr/local/lib/python310.zip',  '/usr/local/lib/python3.10',  '/usr/local/lib/python3.10/lib-dynload',  '/usr/local/lib/python3.10/site-packages',  '/usr/local/lib/python3.10/site-packages/gitdb/ext/smmap']
Mon, 08 Aug 2022 15:17:00 +0200

Traces

Environment:


Request Method: GET
Request URL: http://squest.example.com/ui/service_catalog/service/6/operation/4/request/

Django Version: 3.2.13
Python Version: 3.10.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'django_celery_results',
 'django_celery_beat',
 'guardian',
 'tempus_dominus',
 'django_node_assets',
 'django_filters',
 'drf_yasg',
 'taggit',
 'martor',
 'django_tables2',
 'dbbackup',
 'service_catalog',
 'resource_tracker',
 'profiles',
 'monitoring',
 'cachalot',
 'django_cleanup.apps.CleanupConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'Squest.middleware.maintenance.MaintenanceMiddleware']



Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/app/service_catalog/views/customer/catalog_views.py", line 30, in customer_service_request
    form = ServiceRequestForm(request.user, **parameters)
  File "/app/service_catalog/forms/service_request_forms.py", line 62, in __init__
    self.fields.update(get_fields_from_survey(purged_survey_with_validator))
  File "/app/service_catalog/forms/utils.py", line 80, in get_fields_from_survey
    choices=get_choices_from_string(survey_field["choices"]),
  File "/app/service_catalog/forms/utils.py", line 25, in get_choices_from_string
    split_lines = string_with_anti_slash_n.splitlines()

Exception Type: AttributeError at /ui/service_catalog/service/6/operation/4/request/
Exception Value: 'list' object has no attribute 'splitlines'

Version

  • Squest version or GIT commit number: 1.7.2
  • Ansible Tower/AWX version: 21.3.0
@EliasBoulharts
Copy link
Collaborator

Hello,

What is the separator of your list? Maybe a workaround for you: we use a list splitted by line breaks(\n) for our usage.
What is the answer of this API call?
https://<AWX_ADDRESS>/api/v2/job_templates/<JOB_TEMPLATE_ID>/survey_spec/

Thank you!

Regards

@wilf1rst
Copy link
Author

wilf1rst commented Aug 8, 2022

Hello @EliasBoulharts ,

the survey is made into AWX so I assume that AWX choose its own separator.

Here's the parts with a multiple choices questions using the AWX API call:

       {
            "question_name": "multiple",
            "question_description": "",
            "required": true,
            "type": "multiplechoice",
            "variable": "multiple",
            "min": 0,
            "max": 1024,
            "default": "one",
            "choices": [
                "one",
                "two",
                "three"
            ],
            "new_question": true
        }

Tkx for the help

@EliasBoulharts
Copy link
Collaborator

Ok, it seems that they change the behavior in this PR.

The old behavior was:

       {
            "question_name": "multiple",
            "question_description": "",
            "required": true,
            "type": "multiplechoice",
            "variable": "multiple",
            "min": 0,
            "max": 1024,
            "default": "one",
            "choices": "'one'\n'two'\n'three'",
            "new_question": true
        }

We will work on a patch for the next release.

A workaround is to update your survey with a post to force a string splitted by break line.

Example:
image

@wilf1rst
Copy link
Author

wilf1rst commented Aug 8, 2022

Ok thanks for the quick reply.

I will try to update the survey using the API to force a string splitted by break line.

@Sispheor
Copy link
Contributor

Sispheor commented Aug 9, 2022

Done and merged in dev branch.

@Sispheor Sispheor closed this as completed Aug 9, 2022
@EliasBoulharts
Copy link
Collaborator

Merged in master. It is available in the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants