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

Use the Open edX named releases to conditionally import platform objects #289

Merged
merged 2 commits into from
Dec 4, 2020

Conversation

johnbaldwin
Copy link
Contributor

@johnbaldwin johnbaldwin commented Dec 3, 2020

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

NOTE: See @OmarIthawi 's comments and this issue: #290

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
Copy link
Contributor

@OmarIthawi OmarIthawi Dec 4, 2020

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

from courseware.models import StudentModule # noqa pylint: disable=unused-import,import-error

try:
if RELEASE_LINE == 'juniper':
Copy link
Contributor

@OmarIthawi OmarIthawi Dec 4, 2020

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 👇🏼

Suggested change
if RELEASE_LINE == 'juniper':
if RELEASE_LINE in ['juniper', 'koa']:

from lms.djangoapps.certificates.models import GeneratedCertificate # noqa pylint: disable=unused-import,import-error


try:
if RELEASE_LINE == 'juniper':
Copy link
Contributor

@OmarIthawi OmarIthawi Dec 4, 2020

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.

Suggested change
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':
Copy link
Contributor

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!

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
Copy link
Contributor

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

Copy link
Contributor

@OmarIthawi OmarIthawi left a 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...
@johnbaldwin johnbaldwin force-pushed the john/fix-compat-checks-for-junniper branch from 519f8a7 to 6324588 Compare December 4, 2020 20:35
@johnbaldwin
Copy link
Contributor Author

@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 figures.compat.course_grades. See my git commit message for details

@johnbaldwin johnbaldwin merged commit a4546bc into master Dec 4, 2020
@johnbaldwin johnbaldwin deleted the john/fix-compat-checks-for-junniper branch December 4, 2020 21:28
try:
from openedx.core.release import RELEASE_LINE
except ImportError:
# we are pre-ginkgo
RELEASE_LINE = None
raise UnsuportedOpenedXRelease(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good!

@OmarIthawi
Copy link
Contributor

OmarIthawi commented Dec 7, 2020

Thanks @johnbaldwin! I think this is pretty good.

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.

2 participants