-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: anonymous student IDs [BD-13] #32165
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
fix: anonymous student IDs [BD-13] #32165
Conversation
|
Thanks for the pull request, @Agrendalath! When this pull request is ready, tag your edX technical lead. |
xmodule/tests/__init__.py
Outdated
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.
it's probably worth noting that anonymous_ids basically have to be hex strings at this point, because that's what they've always been, and there's content out there that depends on this for randomization behavior. 😞
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.
Am I right in thinking that individualize_anonymous_user_id() is leftover rollout code and that just makes preview behavior incorrect now and doesn't need to be here?
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 guess dealing with that is not worth adding to this PR in terms of risk either way.
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.
It seems to have been added on purpose: #30248.
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.
Yeah, okay, good to not touch... 😛
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.
Misc. note, but now I think I better understand why the anonymous ID parsing in capa content that I've seen has something like this:
import random
try:
randomseed = int(anonymous_student_id, 16)
except:
randomseed = 1
random.seed(randomseed)... so it doesn't blow up the problem in preview where it can't parse because the strings are not hex strings. There's no need to change this behavior–I just put this note here because it was something that was puzzling me.
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.
FWIW, the motivation for that is that they want to have a handful of random variables that are generated the same way for a given student across multiple problems so that they can tie them together. Like if problem 1 asks you to calculate your monthly mortgage payments based on some variables, and then problem 2 asks you what those payments would be if you paid made a $100K payment after the first year, etc.
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.
Unless I'm missing something, the hash function works the same way as int(hex_string, 16) for hex values. It works for non-hex strings, too (without raising an exception).
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 it would actually be a very useful feature if we could assign variables to some namespace that lives across problems and let XBlocks access that–people have basically hacked that together in a few different ways over the years. Maybe as an XBlock service some day, though we'd have to think through the implications pretty critically.
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.
Unless I'm missing something, the hash function works the same way as int(hex_string, 16) for hex values. It works for non-hex strings, too.
Python's builtin hash function is only guaranteed to return consistently within a given run of a Python process, so it would be a bad fit for deriving anything stable.
edx-platform on ormsbee-anonymous-id-xb-service via 🐍 v3.8.12 (tutor_nightly) is 📦 v0.1.0 took 12s
❯ python
Python 3.8.12 (default, Dec 10 2021, 16:41:45)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> hash("Hello World!")
6517261053207716808
>>> hash("Hello World!")
6517261053207716808
>>>
edx-platform on ormsbee-anonymous-id-xb-service via 🐍 v3.8.12 (tutor_nightly) is 📦 v0.1.0 took 2m18s
❯ python
Python 3.8.12 (default, Dec 10 2021, 16:41:45)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> hash("Hello World!")
740855705488943589
>>> hash("Hello World!")
740855705488943589
>>>
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.
Ah, good point. I forgot it's consistent only for numeric types.
xmodule/video_block/video_block.py
Outdated
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.
The VideoBlock does not use the anonymous student ID anywhere. The only usage of the user service is for requesting the ATTR_KEY_REQUEST_COUNTRY_CODE.
ormsbee
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.
Just squash, and I think we're good to go.
899ed17 to
aef43ad
Compare
After changes from openedx#31472, the user service of a "leaf" XBlock gets overridden with the one created for its parent (SequenceBlock). Therefore, the `requires_per_student_anonymous_id` is ignored in these XBlocks. The subsequent renders of an XBlock (e.g., when requesting the solution) use the student-specific IDs. This removes choosing the proper ID (course-specific or student-specific) from the runtime initialization. Instead, both IDs are passed to the user service. There are only two XBlocks that relied on the `requires_per_student_anonymous_id` - `ProblemBlock` and `HtmlBlock`. They now request the "deprecated" (student-specific) user ID directly from the user service.
aef43ad to
aa85257
Compare
|
@Agrendalath 🎉 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. |
1 similar comment
|
EdX Release Notice: This PR has been deployed to the production environment. |
|
More context about the observed issue this PR is fixing, in case anyone comes back to this PR later: Say we’re rendering a
The fix here was to create an explicit new attribute for the old-style, course-agnostic anonymous student IDs in This sort of thing is not a problem for handler invocation, since those XBlock handlers do not currently invoke the gating-style checks that I think that as a follow-up to this, I'd like to discuss the feasibility of removing block-specific handling from |
Description
After changes from #31472, the
userservice of a "leaf" XBlock. gets overridden with the one created for its parent (SequenceBlock). Therefore, therequires_per_student_anonymous_idis ignored in these XBlocks. This removes choosing the proper ID (course-specific or student-specific) from the runtime initialization. Instead, both IDs are passed to theuserservice. The subsequent renders of an XBlock (e.g., when requesting the solution) use the student-specific IDs.There are only two XBlocks that relied on the
requires_per_student_anonymous_id-ProblemBlockandHtmlBlock. They now request the "deprecated" (student-specific) user ID directly from theuserservice.Supporting information
Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.
Testing instructions
Deadline
As soon as possible.