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

tag names update had a bug when tag-synonym has a tag-name as a source-t... #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions askbot/models/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,25 +1265,34 @@ def update_tags(
*IMPORTANT*: self._question_post() has to
exist when update_tags() is called!
"""

if tagnames.strip() == '':
return

previous_tags = list(self.tags.filter(status = Tag.STATUS_ACCEPTED))

ordered_updated_tagnames = [t for t in tagnames.strip().split(' ')]
updated_tagnames_tmp = set(ordered_updated_tagnames)
given_tagnames = [t for t in tagnames.strip().split(' ')]
given_tagnames_set = set(given_tagnames)

#apply TagSynonym
ordered_updated_tagnames = []
updated_tagnames = set()
for tag_name in updated_tagnames_tmp:

#apply TagSynonym
for tag_name in given_tagnames:

try:
given_tagnames_set.remove(tag_name)
except KeyError: # handle duplicates
continue

try:
tag_synonym = TagSynonym.objects.get(source_tag_name=tag_name)
updated_tagnames.add(tag_synonym.target_tag_name)
ordered_updated_tagnames.append(tag_synonym.target_tag.name)
tag_synonym.auto_rename_count += 1
tag_synonym.save()
except TagSynonym.DoesNotExist:
updated_tagnames.add(tag_name)
ordered_updated_tagnames.append(tag_name)
updated_tagnames = set(ordered_updated_tagnames)

previous_tags = list(self.tags.filter(status = Tag.STATUS_ACCEPTED))
previous_tagnames = set([tag.name for tag in previous_tags])
removed_tagnames = previous_tagnames - updated_tagnames

Expand Down