-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
FC-73 pr for edx platform repository (Creating waffle flag for integration towards created_submission in the edx-submission repo) #36258
Draft
gabrielC1409
wants to merge
7
commits into
openedx:master
Choose a base branch
from
aulasneo:PR-create-waffle-switch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,135
−18
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5f86d4d
fix: create function waffle switch for submit data to created_submission
gabrielC1409 b47cdc2
fix: docs ADR complete
gabrielC1409 2fd7b96
test: run test make and pytest
gabrielC1409 422d08e
fix: update waffle switch in edx-platform
gabrielC1409 2998fef
Merge branch 'master' into PR-create-waffle-switch
gabrielC1409 e740acd
Merge branch 'master' into PR-create-waffle-switch
gabrielC1409 82c2ba2
Merge branch 'master' into PR-create-waffle-switch
gabrielC1409 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
############################################################### | ||
Integration of Waffle Switch for XQueue Submission | ||
############################################################### | ||
|
||
Status | ||
****** | ||
|
||
**Pending** *2025-02-11* | ||
|
||
Implementation in progress. | ||
|
||
Context | ||
******* | ||
|
||
In the `edx-platform` repository, there was a need to implement a mechanism that allows conditional execution of a new functionality: sending a student's response within an exercise to the `created_submission` function. This mechanism should be easily toggleable without requiring code changes or deployments. | ||
|
||
Decision | ||
******** | ||
|
||
A `waffle switch` named `xqueue_submission.enabled` was introduced within the Django admin interface. When this switch is activated, it enables the functionality to send data to the `send_to_submission` function, which parses and forwards the data to the `created_submission` function. | ||
|
||
The `created_submission` function resides in the `edx-submissions` repository and is responsible for storing the data in the submissions database. | ||
|
||
Implementation Details | ||
---------------------- | ||
|
||
This functionality was implemented within the `edx-platform` repository by modifying the following files: | ||
|
||
1. **`xmodule/capa/xqueue_interfaces.py`** | ||
- The `waffle switch` **`xqueue_submission.enabled`** was added here. | ||
- This switch is checked before invoking `send_to_submission`, ensuring that the submission logic is only executed when enabled. | ||
|
||
2. **`xmodule/capa/xqueue_submission.py`** | ||
- This file contains the newly implemented logic that parses the student’s response. | ||
- It processes and formats the data before calling `created_submission`, ensuring that it is correctly stored in the **edx-submissions** repository. | ||
|
||
Consequences | ||
************ | ||
|
||
Positive: | ||
--------- | ||
|
||
- **Flexibility:** The use of a `waffle switch` allows administrators to enable or disable the new submission functionality without modifying the codebase or redeploying the application. | ||
- **Control:** Administrators can manage the feature directly from the Django admin interface, providing a straightforward method to toggle the feature as needed. | ||
- **Modular Design:** The logic was added in a way that allows future modifications without affecting existing submission workflows. | ||
|
||
Negative: | ||
--------- | ||
|
||
- **Potential Misconfiguration:** If the `waffle switch` is not properly managed, there could be inconsistencies in submission processing. | ||
- **Admin Overhead:** Requires monitoring to ensure the toggle is enabled when needed. | ||
|
||
References | ||
********** | ||
|
||
- Commit implementing the change: [f50afcc301bdc3eeb42a6dc2c051ffb2d799f868#diff-9b4290d2b574f54e4eca7831368727f7ddbac8292aa75ba4b28651d4bf2bbe6b](https://github.com/aulasneo/edx-platform/commit/f50afcc301bdc3eeb42a6dc2c051ffb2d799f868#diff-9b4290d2b574f54e4eca7831368727f7ddbac8292aa75ba4b28651d4bf2bbe6b) | ||
- Open edX Feature Toggles Documentation: [Feature Toggles — edx-platform documentation](https://docs.openedx.org/projects/edx-platform/en/latest/references/featuretoggles.html) | ||
- `edx-submissions` Repository: [openedx/edx-submissions](https://github.com/openedx/edx-submissions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import json | ||
import pytest | ||
from unittest.mock import Mock, patch | ||
from django.conf import settings | ||
from xmodule.capa.xqueue_submission import XQueueInterfaceSubmission | ||
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator | ||
from opaque_keys.edx.keys import UsageKey, CourseKey | ||
from xblock.fields import ScopeIds | ||
|
||
|
||
@pytest.fixture | ||
def xqueue_service(): | ||
location = BlockUsageLocator(CourseLocator("test_org", "test_course", "test_run"), "problem", "ExampleProblem") | ||
block = Mock(scope_ids=ScopeIds('user1', 'mock_problem', location, location)) | ||
return XQueueInterfaceSubmission() | ||
|
||
|
||
def test_extract_item_data(): | ||
header = json.dumps({ | ||
'lms_callback_url': 'http://example.com/courses/course-v1:org+course+run/xqueue/5/block-v1:org+course+run+type@problem+block@item_id/score_update', | ||
}) | ||
payload = json.dumps({ | ||
'student_info': json.dumps({'anonymous_student_id': 'student_id'}), | ||
'student_response': 'student_answer', | ||
'grader_payload': json.dumps({'grader': 'test.py'}) | ||
}) | ||
with patch('lms.djangoapps.courseware.models.StudentModule.objects.filter') as mock_filter: | ||
mock_filter.return_value.first.return_value = Mock(grade=0.85) | ||
|
||
student_item, student_answer, queue_name, grader, score = XQueueInterfaceSubmission().extract_item_data(header, payload) | ||
|
||
assert student_item == { | ||
'item_id': 'block-v1:org+course+run+type@problem+block@item_id', | ||
'item_type': 'problem', | ||
'course_id': 'course-v1:org+course+run', | ||
'student_id': 'student_id' | ||
} | ||
assert student_answer == 'student_answer' | ||
assert queue_name == 'default' | ||
assert grader == 'test.py' | ||
assert score == 0.85 | ||
|
||
|
||
@pytest.mark.django_db | ||
@patch('submissions.api.create_submission') | ||
def test_send_to_submission(mock_create_submission, xqueue_service): | ||
header = json.dumps({ | ||
'lms_callback_url': 'http://example.com/courses/course-v1:test_org+test_course+test_run/xqueue/5/block-v1:test_org+test_course+test_run+type@problem+block@item_id/score_update', | ||
}) | ||
body = json.dumps({ | ||
'student_info': json.dumps({'anonymous_student_id': 'student_id'}), | ||
'student_response': 'student_answer', | ||
'grader_payload': json.dumps({'grader': 'test.py'}) | ||
}) | ||
|
||
with patch('lms.djangoapps.courseware.models.StudentModule.objects.filter') as mock_filter: | ||
mock_filter.return_value.first.return_value = Mock(grade=0.85) | ||
|
||
mock_create_submission.return_value = {'submission': 'mock_submission'} | ||
|
||
# Llamada a send_to_submission | ||
result = xqueue_service.send_to_submission(header, body) | ||
|
||
# Afirmaciones | ||
assert 'submission' in result | ||
assert result['submission'] == 'mock_submission' | ||
mock_create_submission.assert_called_once_with( | ||
{ | ||
'item_id': 'block-v1:test_org+test_course+test_run+type@problem+block@item_id', | ||
'item_type': 'problem', | ||
'course_id': 'course-v1:test_org+test_course+test_run', | ||
'student_id': 'student_id' | ||
}, | ||
'student_answer', | ||
queue_name='default', | ||
grader='test.py', | ||
score=0.85 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this ADR should be in the https://github.com/openedx/edx-platform/tree/58834c6bdc20fae182eca4aa4ce7402cc14dfd47/xmodule/docs/decisions directory, and the file name should include "xqueue" in it (we have a ton of waffle switches, so the title "create-waffle-switch" is really not specific enough)