feat: [FC-7879] add signal handler to save assignment dates to Conten… - #347
feat: [FC-7879] add signal handler to save assignment dates to Conten…#347kyrylo-kh wants to merge 4 commits into
Conversation
|
Thanks for the pull request, @kyrylo-kh! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
@kyrylo-kh the branch is reporting as out of date, but I don't have the ability to pull in the latest from base. Can you do so an push it up. |
|
@kyrylo-kh sorry, there also seem to be a bunch of failing tests. Perhaps a rebase will also fix this, but please have a look. |
| block_type=assignment.assignment_type, | ||
| defaults={ | ||
| 'policy': models.DatePolicy.objects.get_or_create(abs_date=assignment.date)[0], | ||
| 'assignment_title': assignment.title, |
There was a problem hiding this comment.
This section is a little strange to me. assignment.title is used twice and is unlikely to be the reliably the subsection_name.
There was a problem hiding this comment.
Do you mean it can confuse having subsection_name in model for different type of content?
We wrote description of this in argument:
assignments: List of Assignment instances. Assignments with missing date or
title are skipped (with a warning). Use Assignment.subsection_name for
the containing subsection when available; it is stored separately from
assignment_title.
| course_key_str | ||
| ) | ||
| continue | ||
| models.ContentDate.objects.update_or_create( |
There was a problem hiding this comment.
There's no transactional boundary set here.
There was a problem hiding this comment.
900b00c to
7c7451a
Compare
7c7451a to
906ef14
Compare
bd16f7c to
f1229a9
Compare
f1229a9 to
9e50d46
Compare
| defaults={ | ||
| 'policy': models.DatePolicy.objects.get_or_create(abs_date=assignment.date)[0], | ||
| 'assignment_title': assignment.title, | ||
| 'course_name': course_key.course, |
There was a problem hiding this comment.
Docstring says course_key can be a string; if a string is passed to this fn, a string caller will raise an attribute error. Suggestion: normalize course_key with " _ensure_key(CourseKey, course_key)"
| course_id=course_key, | ||
| location=assignment.block_key, | ||
| field='due', | ||
| block_type=assignment.assignment_type, |
There was a problem hiding this comment.
block_type is used elsewhere as the structural XBlock type. Suggestion: define assignment_type if we need. But a more general question: Is the block_type or assignment_type needed to identify an existing date row?
There was a problem hiding this comment.
Identity question: No. Row identity = (location, field) (unique_together policy,location,field; location encodes course+block). block_type/assignment_type not needed to match.
I moved block_type out of lookup to defaults. c875945
Value now assignment.block_key.block_type (structural: 'sequential'), matching usage everywhere else
| location=assignment.block_key, | ||
| field='due', | ||
| defaults={ | ||
| 'policy': models.DatePolicy.objects.get_or_create(abs_date=assignment.date)[0], |
There was a problem hiding this comment.
Won't this reintroduce the race condition noted in line 430?
There was a problem hiding this comment.
Agree, as @pkulkark mentioned, this get_or_create for policy may be problematic due to race condition with DatePolicy creation mentioned in set_date_for_block.
I believe it's necessary to reuse _set_content_date_policy from set_date_for_block.
Also, it will be good to add a test case against DatePolicy duplicate.
| title: str | ||
| date: datetime | None | ||
| block_key: UsageKey | ||
| assignment_type: str |
There was a problem hiding this comment.
This field doesn't seem to be persisted. Instead assignment.block_key.block_type is used. Either persist it or remove it from the dataclass.
GlugovGrGlib
left a comment
There was a problem hiding this comment.
Thanks, left several suggestions.
In addition, if this PR is planned to be merged after the #346, it's necessary to include version bump and a changelog update for both changes.
| """ | ||
| course_key = _ensure_key(CourseKey, course_key) | ||
| course_key_str = str(course_key) | ||
| with transaction.atomic(): |
There was a problem hiding this comment.
Will be good to have a test case for the atomic boundary in this method
|
|
||
|
|
||
| @dataclass | ||
| class Assignment: |
There was a problem hiding this comment.
suggestion (optional): this dataclass can be extracted into data.py
| location=assignment.block_key, | ||
| field='due', | ||
| defaults={ | ||
| 'policy': models.DatePolicy.objects.get_or_create(abs_date=assignment.date)[0], |
There was a problem hiding this comment.
Agree, as @pkulkark mentioned, this get_or_create for policy may be problematic due to race condition with DatePolicy creation mentioned in set_date_for_block.
I believe it's necessary to reuse _set_content_date_policy from set_date_for_block.
Also, it will be good to add a test case against DatePolicy duplicate.
|
|
||
| class TestUpdateAssignmentDatesForCourse(TestCase): | ||
| """ | ||
| Tests for the update_assignment_dates_for_course task. |
There was a problem hiding this comment.
Looks like the classname and docstring are not correct as this test cases are for the update_or_create_assignments_due_dates
|
|
||
| def test_assignment_with_null_date(self): | ||
| """ | ||
| Test handling assignments with null dates. |
There was a problem hiding this comment.
Suggest adding a case when row already exists and null date is passed
|
|
||
| def setUp(self): | ||
| self.course_key = CourseKey.from_string('course-v1:edX+DemoX+Demo_Course') | ||
| self.course_key_str = str(self.course_key) |
There was a problem hiding this comment.
self.course_key_str and self.staff_user are not used in the test cases, consider removing them
- Fix DatePolicy race: reuse extracted module-level _set_content_date_policy (filter-existing-then-create) instead of DatePolicy.get_or_create, and take block_type out of the ContentDate lookup (identity is course_id/location/field). - block_type now stores the structural XBlock type (block_key.block_type), matching platform usage; drop the unused assignment_type field from Assignment. - Normalize course_key via _ensure_key so a string course_key is accepted. - Tests: rename class to TestUpdateOrCreateAssignmentsDueDates and fix docstring, add DatePolicy-duplicate regression, atomic-rollback, and existing-row+null-date cases; drop unused setUp attributes.
|
Please, take a look at latest commit |
Description
Adds a new signal handler to support saving assignment due dates to the
ContentDatemodel in theedx-whenservice.Key Changes:
Introduces the
_Assignmentdata class to standardize assignment metadata (title, date, block key, type).Implements
update_or_create_assignments_due_dates()to:ContentDateentries with assignment titles, dates, and metadata.block_type,subsection_name, andcourse_name.DatePolicyentries are reused or created as needed.Adds logging and input validation to handle incomplete or invalid assignment data gracefully.
Testing:
Includes a full test suite verifying:
New entries are inserted correctly.
Existing entries are updated when data changes.
Graceful handling of:
DatePolicycreation.