-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix: Issue when delete all tags on import [FC-0036] #135
Conversation
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:
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() |
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.
Because of this change, I think we also need to change the code below:
if child.external_id not in tags: |
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
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.
Good catch! Thanks!
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.
@rpenido It's ready for another review |
LGTM @ChrisChV! 👍
@ormsbee If you have time, could you please review/merge this PR while @bradenmacdonald is off? Thank you! |
@rpenido: I'm also technically off until Jan 2. Is this blocking your work? |
@bradenmacdonald It's ready for another review |
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.
Almost ready to merge. Just some stray print
calls. Thanks.
tests/openedx_tagging/core/tagging/import_export/test_import_plan.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" |
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.
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.
@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. |
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