-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[FAL-2457] Let ModuleSystem use UserService #29190
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
[FAL-2457] Let ModuleSystem use UserService #29190
Conversation
…vice The following ModuleSystem attributes are deprecated by this change, and should be pulled directly from the user service instead: * anonymous_student_id * seed * user_id * user_is_staff Related changes: * Removes the `user` and `anonymous_student_id` parameters from the ModuleService constructor. * Stores anonymous_user_id in XBlockDjangoUserService's opt_attr * Pulls out constants used by DjangoXBlockUserService opt_attr so they can be used in the platform code. * LmsModuleSystem uses the user service created in wrapper function for runtime.publish to avoid requiring the user service to be "needed" by all XBlocks. * LmsModuleSystem no longer checks for instances of XModuleDescriptor when deciding what kind of anonymous_user_id to provide: all XModules are XBlocks, so this check is unnecessary. * XBlockRuntime returns a user service when requested * Adds tests for deprecated ModuleSystem attributes and changes to XBlockDjangoUserService. (cherry picked from commit c41e7fb)
Removes references to these deprecated attributes from the platform code: * runtime.anonymous_student_id * runtime.seed * runtime.user_id * runtime.user_is_staff Related changes: * Ensure that all platform XBlocks which use these attributes "need" the user service. * ProblemBlock: Removes check for existence of runtime.seed attribute in preparation for removal of this attribute from ModuleSystem. * edxnotes: Catches NoSuchServiceError just in case some XBlocks using notes don't have the user service. * UserTagsService refactor: pass user and course_id on creation (cherry picked from commit 7538392)
* UserStubService now takes user, user_is_staff, and anonymous_user_id * get_test_system() creates a UserStubService with an anonymous_user_id of 'student' * Removes references to deprecated ModuleSystem attributes from test code * Fixes and simplifies the ConditionalBlock tests, using get_module provided by TestModuleSystem instead of trying to mock out all the pieces. (cherry picked from commit 927016a)
This bug occurs when get_module_system_for_user is called more than once per request, for blocks with different values for the requires_per_student_anonymous_id property.
|
Thanks for the pull request, @pomegranited! I've created OSPR-6198 to keep track of it in JIRA, where we prioritize reviews. Please note that it may take us up to several weeks or months to complete a review and merge your PR. Feel free to add as much of the following information to the ticket as you can:
All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here. Please let us know once your PR is ready for our review and all tests are green. |
…oUserService This user object is shared between invocations, and so the anonymous_user_id gets altered for different types of blocks.
| assert vertical_runtime.anonymous_student_id == anonymous_id_for_user(self.user, self.course.id) | ||
|
|
||
| # Ensure the problem runtime's anonymous student ID is unchanged after the above call. | ||
| assert problem_runtime.anonymous_student_id == anonymous_id_for_user(self.user, None) |
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.
Without a14f7e5. this test fails with:
AssertionError: assert 'e9018d2873e89d4dc26ea4d7ef631a1f' == '8538ca55520679e6d31b0c709d19e640'
- 8538ca55520679e6d31b0c709d19e640
+ e9018d2873e89d4dc26ea4d7ef631a1f
Stacktrace
self = <lms.djangoapps.courseware.tests.test_module_render.LmsModuleSystemShimTest testMethod=test_anonymous_student_id_bug>
def test_anonymous_student_id_bug(self):
"""
Verifies that subsequent calls to get_module_system_for_user have no effect on each block runtime's
anonymous_student_id value.
"""
problem_runtime, _ = render.get_module_system_for_user(
self.user,
self.student_data,
self.problem_descriptor,
self.course.id,
self.track_function,
self.xqueue_callback_url_prefix,
self.request_token,
course=self.course,
)
# Ensure the problem block returns a per-user anonymous id
assert problem_runtime.anonymous_student_id == anonymous_id_for_user(self.user, None)
vertical_runtime, _ = render.get_module_system_for_user(
self.user,
self.student_data,
self.descriptor,
self.course.id,
self.track_function,
self.xqueue_callback_url_prefix,
self.request_token,
course=self.course,
)
# Ensure the vertical block returns a per-course+user anonymous id
assert vertical_runtime.anonymous_student_id == anonymous_id_for_user(self.user, self.course.id)
# Ensure the problem runtime's anonymous student ID is unchanged after the above call.
> assert problem_runtime.anonymous_student_id == anonymous_id_for_user(self.user, None)
E AssertionError: assert 'e9018d2873e89d4dc26ea4d7ef631a1f' == '8538ca55520679e6d31b0c709d19e640'
E - 8538ca55520679e6d31b0c709d19e640
E + e9018d2873e89d4dc26ea4d7ef631a1f
lms/djangoapps/courseware/tests/test_module_render.py:2673: AssertionError
|
Your PR has finished running tests. There were no failures. |
|
@pomegranited Thank you for your contribution. Please let me know once this is ready for our review. |
|
@symbolist This PR is ready for your review. CC @ormsbee @natabene |
symbolist
left a comment
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.
@pomegranited Thanks!
- I tested this as per instructions.
- I read through the code
- I checked for accessibility issues. N/A
- Includes documentation
@ormsbee This is ready for merge as well.
|
@pomegranited 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
|
EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production. |
|
EdX Release Notice: This PR has been deployed to the production environment. |
|
Hooray, thank you for helping to diagnose the issue here @ormsbee, so we could get this change merged! |
Description
Re-submits the changes from https://github.com/edx/edx-platform/pull/28440 which were reverted by https://github.com/edx/edx-platform/pull/28857, and fixes the bug that caused this revert.
Initial step towards combining the ModuleSystem and DescriptorSystem classes.
Adds a shim which deprecates these ModuleSystem attributes, pulling them from the
userservice instead of requiring them in the constructor.anonymous_student_idseeduser_iduser_is_staffThis change is only a refactoring, and should not affect Learners, Course Authors, or anyone else using edx-platform.
Supporting information
Testing instructions
LMS: https://pr29190.sandbox.opencraft.hosting
honor@example.com/edx)Studio: https://studio.pr29190.sandbox.opencraft.hosting
staff@example.com/edx)Test the anonymous User ID bug:
This bug occurs only in the Legacy Course Experience mode, for Problem blocks which rely on the
anonymous_student_idcontext variable.For OpenCraft staff:
Login to sandbox as a demo staff (
staff@example.com/edx)Visit the Anonymous User ID Test Course and navigate to the example problem in the Legacy Course Experience.
This problem is expecting the ProblemBlock's anonymous student ID as an answer.
If verifying the bug exists: note that the answer expected when you first view the problem in the Legacy experience changes after you've submitted the problem.
If verifying that the bug is fixed: ensure that the answer expected remains consistent after submitting the problem.
Deadline
ASAP please -- the BD-13 project deliverables are in jeopardy because of delays incurred by this issue.