Skip to content

Conversation

@bradenmacdonald
Copy link
Member

OC-1003

This fixes TNL-3563.

The pb-dashboard block was not loading due to a bizarre combination of factors, brought into play by the recent django-rest-framework upgrade.

Details:

The error was being reported as:

  File "/edx/xblocks/xblock-problem-builder/problem_builder/dashboard.py", line 415, in student_view
    value = sub_api.get_submissions(mcq_submission_key, limit=1)[0]["answer"]
AttributeError: 'NoneType' object has no attribute 'get_submissions'

To get the true error, I had to remove a try: ... except ImportError wrapper, and then we can see the real cause:

Traceback (most recent call last):
  File "manage.py", line 116, in <module>
    execute_from_command_line([sys.argv[0]] + django_args)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/edx/app/edxapp/edx-platform/cms/djangoapps/contentstore/__init__.py", line 2, in <module>
    import contentstore.signals
  File "/edx/app/edxapp/edx-platform/cms/djangoapps/contentstore/signals.py", line 9, in <module>
    from contentstore.courseware_index import CoursewareSearchIndexer, LibrarySearchIndexer
  File "/edx/app/edxapp/edx-platform/cms/djangoapps/contentstore/courseware_index.py", line 340, in <module>
    class CoursewareSearchIndexer(SearchIndexerBase):
  File "/edx/app/edxapp/edx-platform/cms/djangoapps/contentstore/courseware_index.py", line 353, in CoursewareSearchIndexer
    UNNAMED_MODULE_NAME = _("(Unnamed)")
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 86, in ugettext
    return _trans.ugettext(message)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/monkey_patch/django_utils_translation.py", line 70, in dont_translate_empty_string
    message = function(message)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 278, in ugettext
    return do_translate(message, 'ugettext')
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 268, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 183, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 160, in _fetch
    app = import_module(appname)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/edx/app/edxapp/venvs/edxapp/src/edx-sga/edx_sga/__init__.py", line 1, in <module>
    from .sga import StaffGradedAssignmentXBlock
  File "/edx/app/edxapp/venvs/edxapp/src/edx-sga/edx_sga/sga.py", line 24, in <module>
    from submissions import api as submissions_api
  File "/edx/app/edxapp/venvs/edxapp/src/edx-submissions/submissions/api.py", line 16, in <module>
    from submissions.serializers import (
  File "/edx/app/edxapp/venvs/edxapp/src/edx-submissions/submissions/serializers.py", line 42, in <module>
    class SubmissionSerializer(serializers.ModelSerializer):
  File "/edx/app/edxapp/venvs/edxapp/src/edx-submissions/submissions/serializers.py", line 54, in SubmissionSerializer
    attempt_number = IntegerField(min_value=0)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/fields.py", line 721, in __init__
    message = self.error_messages['min_value'].format(min_value=self.min_value)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/functional.py", line 108, in __wrapper__
    res = func(*self.__args, **self.__kw)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 86, in ugettext
    return _trans.ugettext(message)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/monkey_patch/django_utils_translation.py", line 70, in dont_translate_empty_string
    message = function(message)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 278, in ugettext
    return do_translate(message, 'ugettext')
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 268, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 183, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 160, in _fetch
    app = import_module(appname)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/edx/xblocks/xblock-problem-builder/problem_builder/__init__.py", line 4, in <module>
    from .dashboard import DashboardBlock
  File "/edx/xblocks/xblock-problem-builder/problem_builder/dashboard.py", line 36, in <module>
    from .mcq import MCQBlock
  File "/edx/xblocks/xblock-problem-builder/problem_builder/mcq.py", line 31, in <module>
    from .sub_api import sub_api, SubmittingXBlockMixin
  File "/edx/xblocks/xblock-problem-builder/problem_builder/sub_api.py", line 25, in <module>
    from submissions import api as sub_api
ImportError: cannot import name api

Essentially, two django apps (cms.djangoapps.contentstore and rest_framework) are calling ugettext() at import time (i.e. when the CMS starts up), and as you can see in the trace above, this leads to a circular import of the edx-submissions API.

Fix:
A complete fix would probably involve changing ugettext to ugettext_lazy in any import-time code of all django apps used by the platform, but that is an involved undertaking and can lead to subtle bugs.

So I have worked around the issue by fixing problem-builder so it doesn't load dashboard.py when imported as a django app (which was not necessary). This does change the import path for the XBlock, but I'm not aware of any third party code that would be using that import.

@bradenmacdonald bradenmacdonald force-pushed the fix-sub_api-load-issue-oc-1003 branch from 83549dd to 55e1e83 Compare October 10, 2015 06:49
@bradenmacdonald bradenmacdonald force-pushed the fix-sub_api-load-issue-oc-1003 branch from 55e1e83 to 7263e34 Compare October 10, 2015 07:06
@antoviaque
Copy link
Member

It seem like a good approach given the explanations you've put in the description, and a relatively straightforward change. I'm only with a tablet now so I can't test the change - I'll see if someone else from the team can take care of it tomorrow morning. 👍 once this has been tested.

@itsjeyd
Copy link
Member

itsjeyd commented Oct 12, 2015

👍

@macdiesel
Copy link

I'm good with this approach. The imports in __init__.py were likely to cause issues with the django 1.8 upgrade anyway. 👍

bradenmacdonald added a commit that referenced this pull request Oct 13, 2015
Fix: Don't import all the problem builder blocks when the django app is loaded
@bradenmacdonald bradenmacdonald merged commit 1cb40ca into edx-release Oct 13, 2015
@bradenmacdonald bradenmacdonald deleted the fix-sub_api-load-issue-oc-1003 branch October 13, 2015 20:48
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

Successfully merging this pull request may close these issues.

5 participants