Skip to content
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

Merged
merged 10 commits into from
Jul 22, 2021

Conversation

bethanyaconnor
Copy link
Contributor

@bethanyaconnor bethanyaconnor commented Jul 19, 2021

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:

  1. (This PR) Add get_published_state and get_pilot_experiment methods to scripts, which reads from the script first then the unit group (if there is one).
    • Scripts that differ from their unit group:
[levelbuilder] dashboard > Script.all.select {|s| s.unit_group && s.published_state != s.unit_group.published_state}.map(&:name)
=> ["csp-post-survey", "csp3-research-mxghyt", "csp3-a", "csd-post-survey-2018", "csp-post-survey-2018", "time4cs-experiment-unit-2", "time4cs-control-unit-1"]
[levelbuilder] dashboard > Script.all.select {|s| s.unit_group && s.pilot_experiment != s.unit_group.pilot_experiment}.map(&:name)
=> ["time4cs-experiment-unit-2", "time4cs-control-unit-1"]
  1. (Allow the script published_state to be null #41616) Allow published_state on scripts to be null
  2. On levelbuilder, null out the published_state of any scripts in unit groups.
    • 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 }
  3. (Don't set script published state on course edit #41617, still in draft) Remove the code that sets the published_state and pilot_experiment on scripts within unit groups

(Steps below may not be done by me)

  1. Update the course overview page to handle scripts that have a different published_state than its unit group
  2. Add the published_state dropdown back to the script edit page for scrips within courses

ARCHIVE:

  1. (This PR) Read published_state and pilot_experiment from the unit_group if a script is in a unit_group. Because these are set to be the same from the course edit page, there should be no user-facing impact.
  2. (Allow the script published_state to be null #41616) Allow published_state on scripts to be null
  3. (Don't set script published state on course edit #41617, still in draft) Remove the code that sets the published_state and pilot_experiment on scripts within unit groups
  4. On levelbuilder, null out the published_state of any scripts in unit groups.
    • 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)

  1. Update the course overview page to handle scripts that have a different published_state than its unit group
  2. Modify get_published_state (the method added in this PR) to look for the script's published_state before it's unit group
  3. Add the published_state dropdown back to the script edit page for scrips within courses

Links

Testing story

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@bethanyaconnor bethanyaconnor marked this pull request as ready for review July 21, 2021 14:30
@bethanyaconnor bethanyaconnor requested a review from a team July 21, 2021 14:30
@@ -1108,6 +1108,7 @@ def create_script_tree(
)
CourseOffering.add_course_offering(script)
end
script.reload
Copy link
Contributor Author

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?

Copy link
Member

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:

  1. ActiveRecord objects like script here cache what they know about the state of the DB
  2. 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).
  3. however, in this case, CourseOffering.add_course_offering calls CourseVersion.add_course_version, which updates an associated object of the script object without actually touching the script object:
    course_version = CourseVersion.find_or_initialize_by(
    therefore, the script object has stale cached contents, and still thinks it does not have a course_version.
  4. 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 = ...

Copy link
Member

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

Copy link
Contributor Author

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.

@bethanyaconnor bethanyaconnor changed the title Read published_state from unit_group if script is in one Read published_state and pilot_experiment from unit_group if script is in one Jul 21, 2021
@bethanyaconnor bethanyaconnor merged commit 7d9f7d9 into staging Jul 22, 2021
@bethanyaconnor bethanyaconnor deleted the read-published-state-from-unit-group branch July 22, 2021 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants