acangiani / django-tagging

Automatically exported from code.google.com/p/django-tagging
Other
1 stars 0 forks source link

bug when entering duplicate tags #87

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
when using twice the same tag TagManager breaks in update_tags.

Our solution is : 

Index: models.py
===================================================================
--- models.py   (révision 127)
+++ models.py   (copie de travail)
@@ -43,7 +43,7 @@

tag__in=tags_for_removal).delete()
         # Add new tags
         current_tag_names = [tag.name for tag in current_tags]
-        for tag_name in updated_tag_names:
+        for tag_name in set(updated_tag_names):
             if tag_name not in current_tag_names:
                 tag, created = self.get_or_create(name=tag_name)
                 TaggedItem._default_manager.create(tag=tag, object=obj)

Original issue reported on code.google.com by pierrer...@yahoo.fr on 16 Jan 2008 at 10:32

GoogleCodeExporter commented 9 years ago
digging into it a little bit, we figured out the best solution is to prevent 
double
tag in the strip_split function called by parse_tag_input

Index: utils.py
===================================================================
--- utils.py    (révision 127)
+++ utils.py    (copie de travail)
@@ -90,7 +90,7 @@
         return []

     words = [w.strip() for w in input.split(delimiter)]
-    return [w for w in words if w]
+    return list(set([w for w in words if w]))

 def edit_string_for_tags(tags):
     """

Original comment by pierrer...@yahoo.fr on 16 Jan 2008 at 10:49

GoogleCodeExporter commented 9 years ago
Can you give an example of some tag input which is giving you problems?
parse_tag_input already ensures there are no duplicates by doing this before it
returns the list of words, so updated_tag_names should already be unique:

   words = list(set(words))

The following test (in tagging.tests.tests) currently passes:

   >>> parse_tag_input('"two", one, one, two, "one"')
   [u'one', u'two']

Original comment by jonathan.buchanan on 16 Jan 2008 at 11:11

GoogleCodeExporter commented 9 years ago
Argh, unless you only have a space-delimited string, that is!

Failed example:
    parse_tag_input('one one two two')
Expected:
    [u'one', u'two']
Got:
    [u'one', u'one', u'two', u'two']

Original comment by jonathan.buchanan on 16 Jan 2008 at 11:15

GoogleCodeExporter commented 9 years ago
Fixed in revision 128 - thanks for the report.

Original comment by jonathan.buchanan on 16 Jan 2008 at 11:23