apluslms/mooc-grader

Aplus-json export crashes in trilingual courses

markkuriekkinen opened this issue · 4 comments

mooc-grader aplus-json export crashes in trilingual courses (mooc-grader v1.7)

  File "/srv/grader/util/export.py", line 264, in list_enumerate
      return zip_longest(*lists, fillvalue=default)
  TypeError: zip_longest argument #2 must support iteration

It looks like the code should combine fields from different languages, but the third language becomes None sometimes (in a questionnaire). None causes a crash since it is not an iterable for zip_longest. The value should be fields from YAML such as [{'title': '', 'fields': None}].

Longer error traceback:

Traceback:
File "/venv_moocgrader/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)
File "/venv_moocgrader/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/mooc-grader/access/views.py" in aplus_json
  238.             mf["children"] = children_recursion(m)
File "/mooc-grader/access/views.py" in children_recursion
  230.             of["children"] = children_recursion(o)
File "/mooc-grader/access/views.py" in children_recursion
  227.                 of = export.exercise(request, course, exercise, of)
File "/mooc-grader/util/export.py" in exercise
  66.     form, i18n = form_fields(languages, exercises)
File "/mooc-grader/util/export.py" in form_fields
  180.             for fs in list_enumerate(list_get(fgs, 'fields', []), {}):
File "/mooc-grader/util/export.py" in list_enumerate
  266.     return zip_longest(*lists, fillvalue=default)
Exception Type: TypeError at /test-course-trilingual/aplus-json
Exception Value: zip_longest argument #3 must support iteration

This is somehow related to the yaml generation functionality. For example, the structure of links1_chapter2.yaml looks like this:

fieldgroups:
- fields|i18n:
    en:
    - more|i18n:
        en: ...
        fi: ...
    sv:
    - more: ...

Finnish doesn't have its own top level element. Instead, the Finnish translations are listed under en. This causes the Finnish field list to be None, which crashes zip_longest because one of its arguments was None. If I fix the yaml files manually by duplicating the en element and renaming it to fi, it no longer crashes.

So, which component here is working incorrectly?

  • Should the component that generates the yaml files produce different results?
  • Or should mooc-grader be able to load the yaml file even if its structure is like I decribed in the previous comment?

If it is the latter, I think the method ConfigParser._process_exercise_data is responsible for loading the yaml files, and it can't handle that file structure.

@skulonen I think a-plus-rst-tools is very broken with three languages. Compare the built yaml file to the two-lingual course that works correctly (apluslms/test-course branch multilang). The three-lingual version is not only missing languages, but also contains languages in the wrong level.

Therefore, the first priority is to fix the three-lingual course compilation in a-plus-rst-tools.

Two-lingual course looks like this:

fieldgroups:
- fields:
  - more|i18n:
      en: English text
      fi: Tekstiä suomeksi