-
Notifications
You must be signed in to change notification settings - Fork 37
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
Use the Open edX named releases to conditionally import platform objects #289
Conversation
figures/compat.py
Outdated
from courseware.models import StudentModule # noqa pylint: disable=unused-import,import-error | ||
|
||
try: | ||
if RELEASE_LINE == 'juniper': | ||
from lms.djangoapps.courseware.courses import get_course_by_id # noqa pylint: disable=unused-import,import-error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should work fine in Koa but we can make it future proof. See 👇🏼
$ git checkout open-release/koa.master
$ git grep get_course_by_id
lms/djangoapps/discussion/django_comment_client/base/views.py:from lms.djangoapps.courseware.courses import get_course_by_id
figures/compat.py
Outdated
from courseware.models import StudentModule # noqa pylint: disable=unused-import,import-error | ||
|
||
try: | ||
if RELEASE_LINE == 'juniper': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should work fine in Koa but we can make it future proof. See 👇🏼
if RELEASE_LINE == 'juniper': | |
if RELEASE_LINE in ['juniper', 'koa']: |
figures/compat.py
Outdated
from lms.djangoapps.certificates.models import GeneratedCertificate # noqa pylint: disable=unused-import,import-error | ||
|
||
|
||
try: | ||
if RELEASE_LINE == 'juniper': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works with Koa as well.
if RELEASE_LINE == 'juniper': | |
if RELEASE_LINE in ['juniper', 'koa']: |
# koa
lms/djangoapps/instructor_analytics/basic.py:from lms.djangoapps.courseware.models import StudentModule
try: | ||
from opaque_keys.edx.django.models import CourseKeyField # noqa pylint: disable=unused-import,import-error | ||
except ImportError: | ||
if RELEASE_LINE == 'ginkgo': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is future-proof. Great!
figures/compat.py
Outdated
from lms.djangoapps.courseware.courses import get_course_by_id # noqa pylint: disable=unused-import,import-error | ||
except ImportError: | ||
# Backward compatibily for pre-Juniper releases | ||
else: # Backward compatibily for pre-Juniper releases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is not future proof.
Those imports would work but are not future-proof. To fix it needs to be restructured in the following form from the oldest to the most recent release:
if ginkgo or hawthorn:
import # old import
else: # all future releases
import # future proof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to specify that all my previous comments where non-blockers. LGTM. Please feel free to merge. Also, thanks for making the issue #290.
This commit exists to address the problem that a RuntimeError can be raised instead of an ImportError when importing objects from ed-platform. The options to fix are check for ImportError AND RuntimeError. However, we opt (at least for now) to check the Open edX named release to conditionally import objects when the namespace has changed between named releases. Here is an example of the error when only ImportError is handled: ``` RuntimeError: Conflicting 'studentmodule' models in application 'courseware': <class 'courseware.models.StudentModule'> and <class 'lms.djangoapps.courseware.models.StudentModule'>. ``` NOTE: This may break Juniper compat as it was not tested in a live Juniper devstack This commit also addresses #290 We are missing test coverage for figures.compat.course_grade, but this requires some thinking because for the ginkgo test case, we need to mock all the imports as we run this test agnostically (this may be the only test that doesn't or is very close to not relying on figures 'mocks' test infrastructure. To test 'course_grade' we need to check that CourseGradeFactory().create(...) is called for Ginkgo, and 'read' is called for everyone else. BUT we are already mocking CourseGradeFactory so the import doesn't fail and attempts I made so far to get "course_grade_factory_mock.created.assert_called()" have failed. So I ran out of time and punting until later to get test coverage here Also, we've mashed up a chain of mocks for three tests. We are effectively running each test to run each of the supported Open edX platform releases: Ginkgo, Hawthorn, Juniper. This could use some rethinking...
519f8a7
to
6324588
Compare
@OmarIthawi Thanks and I'm merging this in. Take another look. I believe I addressed your comments. Only thing I think needs to be addressed is getting test coverage for |
try: | ||
from openedx.core.release import RELEASE_LINE | ||
except ImportError: | ||
# we are pre-ginkgo | ||
RELEASE_LINE = None | ||
raise UnsuportedOpenedXRelease( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good!
Thanks @johnbaldwin! I think this is pretty good. |
This commit exists to address the problem that a RuntimeError can be
raised instead of an ImportError when importing objects from
ed-platform.
The options to fix are check for ImportError AND RuntimeError. However,
we opt (at least for now) to check the Open edX named release to
conditionally import objects when the namespace has changed between
named releases.
Here is an example of the error when only ImportError is handled:
NOTE: This may break Juniper compat as it was not tested in a live
Juniper devstack
NOTE: See @OmarIthawi 's comments and this issue: #290