Skip to content

Commit 3cb02ec

Browse files
Merge PR #323: Import from common.djangoapps.student.models more reliably
2 parents b8e9ce6 + 19a56a0 commit 3cb02ec

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

problem_builder/models.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@
2020

2121
# Imports ###########################################################
2222

23-
from django.conf import settings
2423
from django.contrib.auth.models import User
2524
from django.db import models
2625
from django.db.models.signals import pre_delete
2726

2827
try:
29-
# workaround so we don't explicitly import the AnonymousUserId model from LMS
30-
if "common.djangoapps.student.apps.StudentConfig" in settings.INSTALLED_APPS:
31-
# Koa and beyond:
28+
# Koa and earlier: use shortened import path.
29+
# This will raise a warning in Koa, but that's OK.
30+
from student.models import AnonymousUserId
31+
except Exception: # pylint: disable=broad-except
32+
# (catch broadly, since the exception could manifest as either an ImportError
33+
# or an EdxPlatformDeprecatedImportError, the latter of which is not a subclass
34+
# of the former, and only exists on edx-platform master between Koa and Lilac).
35+
try:
36+
# Post-Koa: we must use the full import path.
3237
from common.djangoapps.student.models import AnonymousUserId
33-
else:
34-
# Juniper and earlier
35-
from student.models import AnonymousUserId
36-
except ImportError:
37-
# Not running the LMS (e.g. tests)
38-
AnonymousUserId = None
38+
except ImportError:
39+
# If we get here, we are not running within edx-platform
40+
# (e.g., we are running problem-builder unit tests).
41+
AnonymousUserId = None
3942

4043

4144
# Classes ###########################################################

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# Constants #########################################################
3030

31-
VERSION = '4.1.9'
31+
VERSION = '4.1.10'
3232

3333
# Functions #########################################################
3434

0 commit comments

Comments
 (0)