-
Notifications
You must be signed in to change notification settings - Fork 3
adjust department names #1253
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
adjust department names #1253
Conversation
…id, not on the name property which could change
…ch_filter instead of name because name can change, and search_filter should stay the same since it's based on department_id
channels/plugins.py
Outdated
| elif department.school and (overwrite or not channel): | ||
| channel, _ = Channel.objects.update_or_create( | ||
| search_filter=f"department={department.department_id}", | ||
| name=slugify(department.name), |
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.
Remove this line or there will be channels for both the old and new name
Might be good to add a unit test for this condition too (update an existing channel with different name)
mbertrand
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.
👍
What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/4838
Description (What does it do?)
This PR updates 4 department names as noted in the above issue.
update_dateandcreated_dateinfo was also stripped from the JSON fixtures, as it's irrelevant and confuses theupdate_or_createfunction that the info is passed to. The utility functions that load this data were previously matching theirupdate_or_createcalls based on thenameproperty of the school or department, which is incorrect. They should instead be matching on their ID columns;department_idfor departments andidfor schools. This ensures that you can update the name and not get integrity errors likedjango.db.utils.IntegrityError: duplicate key value violates unique constraint "learning_resources_learningresourcedepartmentnew_pkey". Another issue here was thebackpopulate_resource_channelscommand, which runsupdate_or_createbased on a slugified version of the department name for departments. Since the name is changing here, if the command was run as-is a new channel would be created instead of updating the existing one. This was changed to update channel based onsearch_filter, since it is based ondepartment_idwhich is actually constant.How can this be tested?
mit-openon this branchdocker compose exec web ./manage.py update_departments_schoolsdocker compose exec web ./manage.py backpopulate_resource_channels --department --overwrite