Skip to content

Conversation

@pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Nov 2, 2021

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 user service instead of requiring them in the constructor.

  • anonymous_student_id
  • seed
  • user_id
  • user_is_staff

This 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

  1. Login as a demo learner (honor@example.com / edx)
  2. Browse around the Demo course and ensure that blocks render as expected, and that you can submit answers to problems.
  3. Switch to the Legacy Course Experience and browse around in that too.

Studio: https://studio.pr29190.sandbox.opencraft.hosting

  1. Login as a demo staff (staff@example.com / edx)
  2. Navigate to the Demo course and browse through the blocks. Ensure they render and edit as expected.
  3. Check that you can submit answers to problems, and save changes to blocks.
  4. Preview unpublished changes and ensure they render as expected.
  5. Publish changes, and ensure they render in the LMS as expected.

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_id context variable.

For OpenCraft staff:

  • Appserver 1 contains the broken code, so you can verify the bug there.
  • Appserver 3 is running the fixed code on this branch, so you can activate that appserver to verify the bug is fixed.
  1. Login to sandbox as a demo staff (staff@example.com / edx)

  2. 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.

  3. 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.

…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.
@openedx-webhooks
Copy link

openedx-webhooks commented Nov 2, 2021

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:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

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.

@openedx-webhooks openedx-webhooks added needs triage open-source-contribution PR author is not from Axim or 2U labels Nov 2, 2021
@pomegranited pomegranited marked this pull request as draft November 2, 2021 09:19
…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)
Copy link
Contributor Author

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

See https://build.testeng.edx.org/job/edx-platform-python-pipeline-pr/36211/testReport/junit/lms.djangoapps.courseware.tests.test_module_render/LmsModuleSystemShimTest/Run_Tests___lms_unit___test_anonymous_student_id_bug/

@edx-status-bot
Copy link

Your PR has finished running tests. There were no failures.

@natabene
Copy link
Contributor

natabene commented Nov 2, 2021

@pomegranited Thank you for your contribution. Please let me know once this is ready for our review.

@openedx-webhooks openedx-webhooks added waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. and removed needs triage labels Nov 3, 2021
@pomegranited pomegranited marked this pull request as ready for review November 3, 2021 04:38
@openedx-webhooks openedx-webhooks added needs triage and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Nov 3, 2021
@pomegranited
Copy link
Contributor Author

@symbolist This PR is ready for your review. CC @ormsbee @natabene

Copy link
Contributor

@symbolist symbolist left a 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.

@ormsbee ormsbee merged commit 15eca3b into openedx:master Nov 8, 2021
@openedx-webhooks
Copy link

@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-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

@pomegranited pomegranited deleted the jill/BD-13-user-service-fix branch November 9, 2021 02:43
@pomegranited
Copy link
Contributor Author

Hooray, thank you for helping to diagnose the issue here @ormsbee, so we could get this change merged!

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

Labels

merged open-source-contribution PR author is not from Axim or 2U

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants