Skip to content

fix: apply user time zone to course start-date filters - #39163

Open
alezconsultant wants to merge 1 commit into
openedx:masterfrom
alezconsultant:alezconsultant/842-start-date-timezone
Open

alezconsultant wants to merge 1 commit into
openedx:masterfrom
alezconsultant:alezconsultant/842-start-date-timezone

Conversation

@alezconsultant

Copy link
Copy Markdown
Contributor

Description

The start_date_on_or_after and start_date_on_or_before params of GET /api/contentstore/v2/home/courses now take a full ISO 8601 datetime with a UTC offset or Z, for example 2027-07-01T00:00:00+04:00. The filter compares them to CourseOverview.start as instants. start_date_on_or_after includes the instant it names, and start_date_on_or_before does too.

The params used to take a plain YYYY-MM-DD date, and the backend treated that date as a UTC day. A user in another time zone who picked a local day could miss a course that Studio shows on that day. For example, a course starting at 2027-06-30T22:00:00Z is July 1 in UTC+4, but the old filter only returned it for June 30.

With the new format the caller decides where its own calendar day starts and ends. The frontend sends the start of the first picked day and the end of the last picked day, both in the user's offset.

A value without an offset is rejected with a 400 whose message asks for one. That covers a naive datetime such as 2027-07-01T00:00:00, a bare date, and an unparseable string. The backend does not assume UTC for a naive value, because that would reproduce the original bug without any visible error.

Changes

  • get_datetime_param in cms/djangoapps/contentstore/api/views/utils.py replaces get_date_param. Nothing else used the old helper.
  • CourseOverview.get_all_courses filters with start__gte and start__lte on the given datetimes.
  • get_courses_accessible_to_user and the HomePageCoursesViewV2 API docs use the new format.

There is no model change and no migration.

Breaking change

Clients that send YYYY-MM-DD now get a 400. The frontend that builds this filter (the Competency Management course search) must send datetimes with an offset. A literal + in a query string decodes to a space, so it has to be percent-encoded as %2B.

Testing instructions

Automated tests, run in the Tutor devstack cms container with --ds=cms.envs.test:

  • cms/djangoapps/contentstore/rest_api/v2/views/tests/test_home.py: 34 passed. test_start_date_range_compares_instants_using_offset creates three courses and asserts that a one-day range sent with a +04:00 offset returns different courses than the same wall-clock range sent as UTC. A ddt test asserts a 400 for malformed values, bare dates, and naive datetimes.
  • openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py: test_get_all_courses_by_start_date_offset_instants and test_get_all_courses_by_start_date_us_timezone cover both sides of UTC, plus a boundary test at the exact instant.
  • cms/djangoapps/contentstore/tests/test_course_listing.py: the params reach get_all_courses through get_courses_accessible_to_user.
  • ruff check is clean on all changed files. pylint was not run.

Manual check against the devstack Studio, with four courses that start at 2040-01-01T00:00:00Z:

Range Status Courses returned
Dec 31 2039, UTC-5 200 4
Jan 1 2040, UTC-5 200 0
Jan 1 2040, UTC+4 200 4
Dec 31 2039, UTC+4 200 0
Jan 1 2040, Z 200 4
Bare date, naive datetime, or garbage 400 none

Other information

  • The frontend change that sends offsets is not part of this PR.
  • Courses with no start date are excluded when a date filter is set. This PR does not change that.

Related to openedx/openedx-core#842

🤖 Generated with Claude Code

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 29, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @alezconsultant!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@alezconsultant
alezconsultant force-pushed the alezconsultant/842-start-date-timezone branch from 2ed2fd6 to b45daf9 Compare September 29, 2026 16:43
@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Sep 29, 2026
@tbain
tbain self-requested a review September 29, 2026 22:55

@tbain tbain left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, looks good to me, and, in a roundabout way Codex.

Codex raises the possible concern:

Bug. Invalid date parameters bypass validation when the user has no accessible courses. In course.py:1064-1069, the function returns before calling get_datetime_param, so malformed, bare-date, or timezone-naive values produce 200 with an empty result instead of the required 400. Parse the parameters before the early return and add a no-courses/no-access regression test.

However it feels like returning a 200 with an empty list is correct in the case it calls out. If there are no courses, that supersedes warning the end-user about a malformed date since there aren't any courses to even compare with.


Raw Codex output:

Details Review verdict: Request changes.

P2

  • Bug. Invalid date parameters bypass validation when the user has no accessible courses. In course.py:1064-1069, the function returns before calling get_datetime_param, so malformed, bare-date, or timezone-naive values produce 200 with an empty result instead of the required 400. Parse the parameters before the early return and add a no-courses/no-access regression test.

The inclusive gte/lte filtering and timezone-aware comparisons otherwise satisfy the ticket’s boundary behavior. No security, database, or performance issues found.

Checks: changed files passed py_compile; local full tests and Ruff were unavailable. The PR’s public CI reports all 40 checks successful, and the PR includes AI attribution and manual testing steps.

@alezconsultant

alezconsultant commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

@tbain
I wasn't change logic, only add full datetime support, as and leave early return for now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs reviewer assigned PR needs to be (re-)assigned a new reviewer open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

4 participants