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

fix: Issue when delete all tags on import [FC-0036] #135

Merged

Conversation

ChrisChV
Copy link
Contributor

@ChrisChV ChrisChV commented Dec 20, 2023

Description

This fix an error when it comes to performing actions on a taxonomy with tags that have external_id=None

More info

Part of: openedx/modular-learning#126

Testing instructions

Please ensure that the tests cover the expected behavior

After merge

  • Create a tag to upload the new version

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 20, 2023
@openedx-webhooks
Copy link

Thanks for the pull request, @ChrisChV! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@@ -136,7 +136,7 @@ def generate_actions(

if replace:
tags_for_delete = {
tag.external_id: tag for tag in self.taxonomy.tag_set.all()
tag.external_id or tag.id: tag for tag in self.taxonomy.tag_set.all()
Copy link
Contributor

@rpenido rpenido Dec 21, 2023

Choose a reason for hiding this comment

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

Because of this change, I think we also need to change the code below:

Context: this is to prevent updating a tag that could already be deleted

The following test (to be put in import_export/test_api.py) reproduce the issue:

    def test_import_removing_with_childs_no_external_id(self) -> None:
        """
        Test import need to remove childs with parents that will also be removed,
        using tags without external_id
        """
        new_taxonomy = Taxonomy(name="New taxonomy")
        new_taxonomy.save()
        level2 = Tag.objects.create(
            id=1000,
            value="Tag 2",
            taxonomy=new_taxonomy,
        )
        level1 = Tag.objects.create(
            id=1001,
            value="Tag 1",
            taxonomy=new_taxonomy,
        )
        level3 = Tag.objects.create(
            id=1002,
            value="Tag 3",
            taxonomy=new_taxonomy,
        )
        level2.parent = level1
        level2.save()

        level3.parent = level3
        level3.save()

        # Import with empty tags, to remove all tags
        importFile = BytesIO(json.dumps({"tags": []}).encode())
        result, _tasks, _plan =  import_export_api.import_tags(
            new_taxonomy,
            importFile,
            ParserFormat.JSON,
            replace=True,
        )
        assert result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rpenido Updated here: b1c4cc9

@ChrisChV
Copy link
Contributor Author

@rpenido It's ready for another review

@rpenido
Copy link
Contributor

rpenido commented Dec 21, 2023

LGTM @ChrisChV! 👍

  • I read through the code
  • I checkout the branch and run the tests
  • I imported tags over a Taxonomy that originated this bug

@ormsbee If you have time, could you please review/merge this PR while @bradenmacdonald is off?

Thank you!

@ormsbee
Copy link
Contributor

ormsbee commented Dec 21, 2023

@rpenido: I'm also technically off until Jan 2. Is this blocking your work?

@rpenido
Copy link
Contributor

rpenido commented Dec 22, 2023

@rpenido: I'm also technically off until Jan 2. Is this blocking your work?

No @ormsbee. This is not urgent and could wait. Sorry to bother you!

Thank you for your response and have a good holiday! 😃

@ChrisChV
Copy link
Contributor Author

@bradenmacdonald It's ready for another review

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

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

Almost ready to merge. Just some stray print calls. Thanks.

tests/openedx_tagging/core/tagging/test_views.py Outdated Show resolved Hide resolved
"#4: Update the parent of <Tag> (tag_4 / Tag 4) from parent "
"<Tag> (tag_3 / Tag 3) to tag_1\n"
"#5: Rename tag value of <Tag> (tag_4 / Tag 4) to 'Tag 4 v2'\n"
"#6: No changes needed for <TagItem> (tag_1 / Tag 1)\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

From a user perspective, it's confusing that this sometimes says <TagItem> and other times says <Tag>. We may need to tweak this in the future, especially if we're trying to display this nicely in the frontend. (Though maybe we also need a JSON version of the plan for that.) I think this is OK for now though.

@bradenmacdonald bradenmacdonald merged commit 3f990b8 into openedx:main Jan 12, 2024
7 checks passed
@openedx-webhooks
Copy link

@ChrisChV 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@bradenmacdonald bradenmacdonald deleted the chris/fix-delete-all-on-import branch January 12, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants