Skip to content

Commit

Permalink
fix: AA-1058: Bust cache when Schedules are updated
Browse files Browse the repository at this point in the history
We had a bug reported where learners would reset their due dates
for their Personalized Learner Schedule, but the dates wouldn't
update. This was a result of the cache key not changing, so this
fix adds in the learner's schedule to the transformer.
  • Loading branch information
Dillon-Dumesnil committed Oct 20, 2021
1 parent a9e78e8 commit 0377738
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[2.2.2] - 2021-10-21
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Bug fix to bust cache when Personalized Learner Schedules are updated.

[2.2.1] - 2021-09-15
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Bug fix for optimization in 2.2.0, to account for missing block_type data.
Expand Down
2 changes: 1 addition & 1 deletion edx_when/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Central source of course block dates for the LMS.
"""

__version__ = '2.2.1'
__version__ = '2.2.2'

default_app_config = 'edx_when.apps.EdxWhenConfig' # pylint: disable=invalid-name
17 changes: 16 additions & 1 deletion edx_when/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

from . import api

try:
from openedx.core.djangoapps.schedules.models import Schedule
# TODO: Move schedules into edx-when
except ImportError:
Schedule = None

try:
from xmodule.modulestore.inheritance import InheritanceMixin
INHERITABLE_FIELDS = set(InheritanceMixin.fields.keys())
Expand Down Expand Up @@ -155,7 +161,16 @@ def transform(self, usage_info, block_structure):
"""
Load override data into blocks.
"""
dates = api.get_dates_for_course(usage_info.course_key, self.user)
schedule = None
if Schedule:
try:
schedule = Schedule.objects.get(
enrollment__user=self.user, enrollment__course__id=usage_info.course_key
)
except Schedule.ObjectDoesNotExist:
pass

dates = api.get_dates_for_course(usage_info.course_key, self.user, schedule=schedule)
for (location, field), date in dates.items():
try:
block_structure.override_xblock_field(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_xblock_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.test import TestCase

from edx_when import api, field_data
from tests.test_models_app.models import DummySchedule
from test_utils import make_items

NUM_OVERRIDES = 6
Expand Down Expand Up @@ -124,8 +125,9 @@ def test_collect(self):
field_data.DateOverrideTransformer.collect(block_structure)
assert block_structure.request_xblock_fields.called_once_with('due', 'start')

@mock.patch('edx_when.models.Schedule', DummySchedule)
@mock.patch('edx_when.api._are_relative_dates_enabled', return_value=True)
def test_transform(self, _mock):
def test_transform(self, _mock, _mock2):
override = datetime.datetime(2020, 1, 1)
api.set_date_for_block(self.items[0][0].course_key, self.items[0][0], 'due', override, user=self.user)
usage_info = mock.MagicMock()
Expand Down

0 comments on commit 0377738

Please sign in to comment.