Skip to content

Conversation

@gumaerc
Copy link
Contributor

@gumaerc gumaerc commented Jul 11, 2024

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_date and created_date info was also stripped from the JSON fixtures, as it's irrelevant and confuses the update_or_create function that the info is passed to. The utility functions that load this data were previously matching their update_or_create calls based on the name property of the school or department, which is incorrect. They should instead be matching on their ID columns; department_id for departments and id for schools. This ensures that you can update the name and not get integrity errors like django.db.utils.IntegrityError: duplicate key value violates unique constraint "learning_resources_learningresourcedepartmentnew_pkey". Another issue here was the backpopulate_resource_channels command, which runs update_or_create based 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 on search_filter, since it is based on department_id which is actually constant.

How can this be tested?

  • Spin up mit-open on this branch
  • Run docker compose exec web ./manage.py update_departments_schools
  • Run docker compose exec web ./manage.py backpopulate_resource_channels --department --overwrite
  • Visit http://localhost:8062/departments
  • Ensure that the changed department names are listed and match what they should be as indicated in the above issue
  • Click on the changed departments and ensure that they lead to a channel page, and that the channel page has been updated with the new department name

@gumaerc gumaerc added the Needs Review An open Pull Request that is ready for review label Jul 11, 2024
@mbertrand mbertrand self-assigned this Jul 11, 2024
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),
Copy link
Member

@mbertrand mbertrand Jul 11, 2024

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 mbertrand added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Jul 11, 2024
@gumaerc gumaerc added Needs Review An open Pull Request that is ready for review and removed Waiting on author labels Jul 11, 2024
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.

👍

@mbertrand mbertrand added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Jul 12, 2024
@gumaerc gumaerc merged commit dcd9c01 into main Jul 12, 2024
@odlbot odlbot mentioned this pull request Jul 12, 2024
4 tasks
@rhysyngsun rhysyngsun deleted the cg/adjust-department-names branch February 7, 2025 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants