Skip to content

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

Merged
bradenmacdonald merged 10 commits into
openedx:mainfrom
open-craft:chris/fix-delete-all-on-import
Jan 12, 2024
Merged

fix: Issue when delete all tags on import [FC-0036]#135
bradenmacdonald merged 10 commits into
openedx:mainfrom
open-craft:chris/fix-delete-all-on-import

Conversation

@ChrisChV

@ChrisChV ChrisChV commented Dec 20, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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.

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()

@rpenido rpenido Dec 21, 2023

Copy link
Copy Markdown
Contributor

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:
https://github.com/openedx/openedx-learning/blob/fb8d16112fa4705fda8f8ac44cd3401cfb08619e/openedx_tagging/core/tagging/import_export/import_plan.py#L96

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@rpenido It's ready for another review

@rpenido

rpenido commented Dec 21, 2023

Copy link
Copy Markdown
Contributor

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

ormsbee commented Dec 21, 2023

Copy link
Copy Markdown
Contributor

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

@rpenido

rpenido commented Dec 22, 2023

Copy link
Copy Markdown
Contributor

@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! 😃

Comment thread openedx_tagging/core/tagging/import_export/actions.py Outdated
Comment thread openedx_tagging/core/tagging/import_export/actions.py Outdated
Comment thread openedx_tagging/core/tagging/models/base.py Outdated
@ChrisChV

Copy link
Copy Markdown
Contributor Author

@bradenmacdonald It's ready for another review

@bradenmacdonald bradenmacdonald left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread tests/openedx_tagging/core/tagging/import_export/test_import_plan.py Outdated
Comment thread tests/openedx_tagging/core/tagging/test_views.py Outdated
"#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
Copy Markdown
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
@openedx-webhooks

Copy link
Copy Markdown

@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.

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