Remove the course_id property on student.CourseEnrollment.

It conflicts with an underlying related field on that model which seems
to be getting at the same value from the related table.

Add logging for incorrectly instantiating CourseEnrollment models.
This is to catch any places that might break this that are outside of
edx-platform. Django won't accept `course` values that aren't
course_overviews so we don't need extra logic to test that `course`
values are of the correct type.

fixup! Remove the course_id property on student.CourseEnrollment.
This commit is contained in:
Feanil Patel
2020-04-02 13:01:50 -04:00
parent c94beec16b
commit 7c115cca24

View File

@@ -13,6 +13,7 @@ file and check it in at the same time as your model changes. To do that,
import hashlib
import inspect
import json
import logging
import uuid
@@ -1094,17 +1095,6 @@ class CourseEnrollment(models.Model):
def course_price(self):
return get_cosmetic_verified_display_price(self.course)
@property
def course_id(self):
return self._course_id
@course_id.setter
def course_id(self, value):
if isinstance(value, six.string_types):
self._course_id = CourseKey.from_string(value)
else:
self._course_id = value
created = models.DateTimeField(auto_now_add=True, null=True, db_index=True)
# If is_active is False, then the student is not considered to be enrolled
@@ -1136,6 +1126,13 @@ class CourseEnrollment(models.Model):
ordering = ('user', 'course')
def __init__(self, *args, **kwargs):
if 'course_id' in kwargs:
course_id = kwargs['course_id']
if isinstance(course_id, str):
kwargs['course_id'] = CourseKey.from_string(course_id)
call_location = "\n".join("%30s : %s:%d" % (t[3], t[1], t[2]) for t in inspect.stack()[::-1])
log.warning("Forced to coerce course_id in CourseEnrollment instantiation: %s", call_location)
super(CourseEnrollment, self).__init__(*args, **kwargs)
# Private variable for storing course_overview to minimize calls to the database.