Skip to content

Commit

Permalink
Merge pull request #68 from edx/mikix/no-schedule
Browse files Browse the repository at this point in the history
Don't warn if we're missing a schedule for relative dates
  • Loading branch information
mikix authored Jan 15, 2021
2 parents 9eb427c + 3f1edcc commit 4b3610c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Change Log
Unreleased
~~~~~~~~~~

[1.3.2] - 2021-01-15
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Don't warn about missing schedules for relative dates.
It happens for legitimate reasons, and the layer above can check instead.

[1.3.1] - 2020-11-19
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Updated travis badge in README.rst to point to travis-ci.com instead of travis-ci.org
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 @@
Your project description goes here.
"""

__version__ = '1.3.1'
__version__ = '1.3.2'

default_app_config = 'edx_when.apps.EdxWhenConfig' # pylint: disable=invalid-name
6 changes: 4 additions & 2 deletions edx_when/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ def get_dates_for_course(course_id, user=None, use_cached=True, schedule=None):
key = (cdate.location.map_into_course(course_id), cdate.field)
try:
dates[key] = cdate.policy.actual_date(schedule, end_datetime, cutoff_datetime)
except ValueError:
log.warning("Unable to read date for %s", cdate.location, exc_info=True)
except models.MissingScheduleError:
# We had a relative date but no schedule. This is permissible in some cases (staff users viewing a course
# they are not enrolled in, for example). Just let it go by.
pass
policies[cdate.id] = key

if user_id:
Expand Down
6 changes: 5 additions & 1 deletion edx_when/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
Schedule = None


class MissingScheduleError(ValueError):
pass


class DatePolicy(TimeStampedModel):
"""
Stores a date (either absolute or relative).
Expand Down Expand Up @@ -51,7 +55,7 @@ def actual_date(self, schedule=None, end_datetime=None, cutoff_datetime=None):
"""
if self.rel_date is not None:
if schedule is None:
raise ValueError(
raise MissingScheduleError(
"Can't interpret relative date {} for {!r} without a user schedule".format(
self.rel_date,
self
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.test import TestCase
from mock import patch

from edx_when.models import ContentDate, DatePolicy
from edx_when.models import ContentDate, DatePolicy, MissingScheduleError
from tests.test_models_app.models import DummyCourse, DummyEnrollment, DummySchedule

User = get_user_model()
Expand Down Expand Up @@ -43,7 +43,7 @@ def test_actual_date(self, abs_date, rel_date, schedule, expected):
@ddt.unpack
def test_actual_date_failure(self, abs_date, rel_date, schedule):
policy = DatePolicy(abs_date=abs_date, rel_date=rel_date)
with self.assertRaises(ValueError):
with self.assertRaises(MissingScheduleError):
policy.actual_date(schedule)

def test_actual_date_schedule_after_end(self):
Expand Down

0 comments on commit 4b3610c

Please sign in to comment.