-
Notifications
You must be signed in to change notification settings - Fork 479
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
Read published_state and pilot_experiment from unit_group if script is in one #41614
Read published_state and pilot_experiment from unit_group if script is in one #41614
Conversation
@@ -1108,6 +1108,7 @@ def create_script_tree( | |||
) | |||
CourseOffering.add_course_offering(script) | |||
end | |||
script.reload |
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 don't know why I needed to do this in so many tests. Anyone have any ideas?
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'm not sure where this is documented, but my general understanding is like this:
- ActiveRecord objects like
script
here cache what they know about the state of the DB - if you use the object to update the contents of the DB as with
script.update!
, the cached data in the model is updated (in addition to the DB contents). - however, in this case,
CourseOffering.add_course_offering
callsCourseVersion.add_course_version
, which updates an associated object of thescript
object without actually touching thescript
object:course_version = CourseVersion.find_or_initialize_by( script
object has stale cached contents, and still thinks it does not have a course_version. - if instead
CourseVersion.add_course_version
looked like this, you might not need to reload after:
def self.add_course_version(course_offering, content_root)
if content_root.is_course?
content_root.course_version = ...
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 is also possible you could keep the add_course_version
method how it is and add a content_root.reload_course_version
call to the end of it, which I just read about here: https://guides.rubyonrails.org/v5.2/association_basics.html#methods-added-by-has-one-association
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.
That makes sense as it seems to be happening in other tests as a result of create :unit_group_unit
which would also not update the active record cache. Curious why these two methods are causing this in so many cases such as this one.
Step 1 of setting up per-unit-in-course published_state.
It turns out that there are some scripts that have a different published_state from their unit group (I believe this is needed for alternative scripts?). New steps:
Script.all.select {|s| s.unit_group.present? && s.published_state == s.unit_group.published_state }.each {|s| s.published_state = nil ; s.save! ; s.write_script_dsl ; s.write_script_json }
(Steps below may not be done by me)
ARCHIVE:
Script.all.select {|s| s.unit_group.present? }.each {|s| s.published_state = nil ; s.save! ; s.write_script_dsl ; s.write_script_json }
(Steps below may not be done by me)
get_published_state
(the method added in this PR) to look for the script's published_state before it's unit groupLinks
Testing story
Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: