Skip to content

Prevent test courses from being overwritten #2262

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

Merged
merged 7 commits into from
May 28, 2025

Conversation

shanbady
Copy link
Contributor

@shanbady shanbady commented May 24, 2025

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/7373

Description (What does it do?)

We have a mechanism for tagging certain courses as being in "test_mode" so that they have their contentfiles ingested into qdrant and opensearch but remain "unpublished". There is an issue where scheduled etl backpopulate tasks overwrite this status and remove contentfiles from the indexes.

How can this be tested?

  1. checkout main
  2. make sure you have some courses populated. in this case we will use mitxonline which has a course intended to be a test course python manage.py backpopulate_mitxonline_data
  3. see that the test_mode on the learning resource is false. also note the id
LearningResource.objects.get(readable_id='course-v1:UAI_SOURCE+UAI.2').test_mode
print(LearningResource.objects.get(readable_id='course-v1:UAI_SOURCE+UAI.2').id)
  1. use the id to mark it as test_mode when fetching contentfiles:
python manage.py backpopulate_mitxonline_files --resource-ids <resource_id> --test-ids <resource_id> --overwrite
  1. note that there are not contentfiles for the course run:
LearningResource.objects.get(readable_id='course-v1:UAI_SOURCE+UAI.2').runs.first().content_files.all()
  1. manually set the run for that course to published:
run = LearningResource.objects.get(readable_id='course-v1:UAI_SOURCE+UAI.2').runs.first()
run.published = True
run.save()

and re-run backpopulate_mitxonline_files --resource-ids <resource_id> --test-ids <resource_id> --overwrite

  1. re-run python manage.py backpopulate_mitxonline_data -> note that the contentfiles for that particular run are gone/removed.
  2. re-run above steps on this branch and note that contentfiles for test_mode=True resources are persisted.
  3. You should also be able to manually set test_mode back to false and re-run the pipeline to see them get removed again
  4. validate that test_mode=True resources do not show up in the search index http://open.odl.local:8063/api/v1/learning_resources_search/?id=

Checklist:

  • Validate this behaves as expected for test_mode=True and test_mode=False course
  • go through the changes and make sure there are no unintended side effects or edge cases this could raise

@shanbady shanbady added Needs Review An open Pull Request that is ready for review and removed Work in Progress labels May 27, 2025
@shanbady shanbady marked this pull request as ready for review May 27, 2025 16:38
@mbertrand mbertrand self-assigned this May 28, 2025
Copy link
Member

@mbertrand mbertrand left a comment

Choose a reason for hiding this comment

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

Works great, just mentioned 1 concern but it might be an irrelevant edge case.

run_id=run_id, learning_resource=learning_resource
).learning_resource.test_mode
):
return None
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it matters, but I suspect that if a "test_mode" course has additional runs added to it later on the edx side, they won't be added here because of these additional lines.


if learning_resource_run.learning_resource.test_mode:
learning_resource_run.published = True
learning_resource_run.save()
Copy link
Member

Choose a reason for hiding this comment

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

I think this could be moved to before the transaction.atomic block so that the change is saved within that block:

if learning_resource.test_mode:
    run_data["published"] = True
    
with transaction.atomic():
    ...etc
    

Also...should all test_mode course runs be automatically set to published=True? Maybe there's a legitimate reason for 1 or more of the runs to not be published?

Copy link
Contributor Author

@shanbady shanbady May 28, 2025

Choose a reason for hiding this comment

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

moved it to before the atomic block. I'm not aware of any consequences of setting them all to published if the course is in test mode and the resource is unpublished. I figure we can patch that when/if the need arises.

Copy link
Member

@mbertrand mbertrand left a comment

Choose a reason for hiding this comment

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

👍

@shanbady shanbady merged commit 1ac164a into main May 28, 2025
13 checks passed
@shanbady shanbady deleted the shanbady/test-course-clobbering-fix branch May 28, 2025 18:15
@odlbot odlbot mentioned this pull request May 28, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review An open Pull Request that is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants