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

Don't warn if we're missing a schedule for relative dates #68

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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