Skip to content

Conversation

@pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Aug 11, 2021

Description

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

Dependent on:

Testing instructions

LMS: https://pr28440.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.pr28440.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.

Deadline

None

@openedx-webhooks
Copy link

openedx-webhooks commented Aug 11, 2021

Thanks for the pull request, @pomegranited! I've created BLENDED-937 to keep track of it in Jira. More details are on the BD-13 project page.

When this pull request is ready, tag your edX technical lead.

@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program needs triage labels Aug 11, 2021
@pomegranited pomegranited marked this pull request as draft August 11, 2021 08:35
@pomegranited pomegranited force-pushed the jill/BD-13-user-service branch 4 times, most recently from 640078b to e029feb Compare August 18, 2021 10:52
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.

Thanks, I have done a pass.

@pomegranited pomegranited marked this pull request as ready for review August 20, 2021 07:22
@pomegranited pomegranited marked this pull request as ready for review August 30, 2021 06:59
@pomegranited pomegranited force-pushed the jill/BD-13-user-service branch from f99e457 to e24a8f7 Compare August 30, 2021 08:31
@pomegranited pomegranited force-pushed the jill/BD-13-user-service branch 2 times, most recently from 1523b7b to 7c24e84 Compare August 31, 2021 07:29
@pomegranited
Copy link
Contributor Author

Hi @ormsbee ! This PR is ready for your eyes. There's a question in the Author Notes that could use your feedback too, when you get a chance. CC @symbolist

@pomegranited pomegranited force-pushed the jill/BD-13-user-service branch from 7c24e84 to 4f95b3b Compare September 2, 2021 02:02
@symbolist
Copy link
Contributor

@pomegranited I missed this earlier:

The UserTagService relies on runtime.anonymous_student_id, which should now be pulled from the UserService instead.
How to deal with a service that depends on another service?

It looks like it only needs the Django User object? Or does it need the UserService for anything else? In general, if a service needs another, the later can be passed in as an init parameter to the former.

@pomegranited
Copy link
Contributor Author

@symbolist I've addressed your last comment, so this should be ready for your final review. CC @ormsbee

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.

  • I tested this by checking changes to HTML and Problem XBlocks, due dates, timed exams.
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation

@symbolist
Copy link
Contributor

@pomegranited Have a couple of questions and then this just needs a rebase!

@pomegranited pomegranited force-pushed the jill/BD-13-user-service branch from 25dce1d to 7cb20bf Compare September 17, 2021 09:13
…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.
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
* 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.
@pomegranited pomegranited force-pushed the jill/BD-13-user-service branch from b20c99f to 927016a Compare September 23, 2021 02:40
@edx-status-bot
Copy link

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

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.

@ormsbee This is ready for merge at a convenient time (preferably early in the day). 🙂

@ormsbee
Copy link
Contributor

ormsbee commented Sep 23, 2021

Talked to @symbolist about this and I'll merge tomorrow morning, around 9 AM EDT.

@pomegranited
Copy link
Contributor Author

Yay!! Thank you @ormsbee and @symbolist !

@ormsbee ormsbee merged commit 3827f4c into openedx:master Sep 24, 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.

text = self.data

user_service = self.runtime.service(self, 'user')
anonymous_student_id = user_service.get_current_user().opt_attrs.get(ATTR_KEY_ANONYMOUS_USER_ID)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@symbolist @ormsbee I was able to reproduce the issue with the flip-flopping anonymous_student_id values and this branch, but only on the legacy courseware view.

Problem blocks have requires_per_student_anonymous_id = True set on their descriptors, and so should be using the per-user anonymous_user_id value.

However, with this branch:

  • When the problem block is first viewed in the legacy courseware view, it incorrectly has the per-course anonymous_user_id in its user service, instead of the per-user anonymous_user_id.
  • When the problem block is viewed in the new learning MFE, or when the problem block is scored via AJAX, it correctly uses the per-user anonymous_user_id.

I hacked a few things and it seems like the runtime (and user service) used to initialize the ProblemBlock in the legacy courseware view isn't actually the problem block's runtime, it's the parent unit's runtime + user service. Does that sound possible? And do you have any idea how/where that's being passed in?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, the child of a block is loaded via https://github.com/edx/edx-platform/blob/master/lms/djangoapps/courseware/module_render.py#L501. Checking what happens inside it with a debugger may provide some insights. You may also want to particularly check what happens when bind_for_student() gets called in these different scenarios on the ProblemBlock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@symbolist CC @ormsbee Here's the line that caused the issue, in DjangoXBlockUserService.init

That same django_user object gets passed through when creating the ProblemBlock's user service, and its parent Vertical and Sequence blocks. I unwisely stored the anonymous_user_id attribute on that shared django_user object (mimicking the user_is_staff attribute storage in the line above), and since the anonymous_user_id value is different for Problem/HTML blocks vs Vertical/Sequence blocks (cf requires_per_student_anonymous_id), it was being altered during rendering.

https://github.com/edx/edx-platform/pull/29190 will address this issue and add a test to verify the fix.

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

Labels

blended PR is managed through 2U's blended developmnt program merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants