Skip to content

Conversation

@ChristopherChudzicki
Copy link
Contributor

What are the relevant tickets?

Fixes https://github.com/mitodl/hq/issues/5858

Description (What does it do?)

When assigning resources to lists (learning paths, userlists), the resource was being added again to lists it was already in. This fixes that.

How can this be tested?

  1. I recommend reproducing the bug on main:
    • Create two learning paths, L1 and L2
    • Add resource to L1
    • re-open the dialog, and add same resource to L2 (keeping L1 checked)
    • You will see that on main, L1 now has two copies of the resource
  2. Check that ☝️ does not happen on this branch, for userlists or for learning resources.

)

# Add new items as necessary
if learning_path_id not in list(current_parent_lists):
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 spend a while trying to debug why my conditional was not working, and it ended up being because (originally) learning_path_id was a string, whereas current_parent_lists was a list of integers.

That motivated me to make the two new serializers for validating request data.

@ChristopherChudzicki ChristopherChudzicki marked this pull request as ready for review October 24, 2024 20:59
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 add some missing docstrings to the tests, and, only if you feel like it, make the suggested change to reduce code duplication.

)
learning_resource_id = serializers.IntegerField()

def validate_learning_resource_id(self, learning_resource_id):
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, but to avoid some code duplication, you could have a BaseListItemsRequestsSerializer with the validate_learrning_resource_id function defined, then have SetUserRequestSerializer and SetLearningPathRequestSerializer inherit from that.

)


def test_set_learning_path_request_serializer():
Copy link
Member

Choose a reason for hiding this comment

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

Add. docstring

assert "learning_resource_id" in invalid.errors


def test_set_userlist_request_serializer():
Copy link
Member

Choose a reason for hiding this comment

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

Add. docstring

)


def test_adding_to_userlist_not_effect_existing_membership(client, user):
Copy link
Member

Choose a reason for hiding this comment

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

missing docstring

@ChristopherChudzicki ChristopherChudzicki merged commit 073bce9 into main Oct 25, 2024
11 checks passed
@rhysyngsun rhysyngsun deleted the cc/list-duplicates branch February 7, 2025 20:39
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