Skip to content

Commit bbc7f25

Browse files
committed
Revert "Fixed issue #28 — properly update TagField tag instance cache when loading the object to keep everything in sync. Thanks ebartels and carljm for the legwork."
This reverts commit 1e829d4. Conflicts: tagging/fields.py tagging/tests/models.py tagging/tests/tests.py
1 parent 5c8ce15 commit bbc7f25

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

tagging/fields.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class TagField(CharField):
1919
def __init__(self, *args, **kwargs):
2020
kwargs['max_length'] = kwargs.get('max_length', 255)
2121
kwargs['blank'] = kwargs.get('blank', True)
22-
kwargs['default'] = kwargs.get('default', '')
2322
super(TagField, self).__init__(*args, **kwargs)
2423

2524
def contribute_to_class(self, cls, name):
@@ -31,9 +30,6 @@ def contribute_to_class(self, cls, name):
3130
# Save tags back to the database post-save
3231
signals.post_save.connect(self._save, cls, True)
3332

34-
# Update tags from Tag objects post-init
35-
signals.post_init.connect(self._update, cls, True)
36-
3733
def __get__(self, instance, owner=None):
3834
"""
3935
Tag getter. Returns an instance's tags if accessed on an instance, and
@@ -57,6 +53,13 @@ class Link(models.Model):
5753
if instance is None:
5854
return edit_string_for_tags(Tag.objects.usage_for_model(owner))
5955

56+
tags = self._get_instance_tag_cache(instance)
57+
if tags is None:
58+
if instance.pk is None:
59+
self._set_instance_tag_cache(instance, '')
60+
else:
61+
self._set_instance_tag_cache(
62+
instance, edit_string_for_tags(Tag.objects.get_for_object(instance)))
6063
return self._get_instance_tag_cache(instance)
6164

6265
def __set__(self, instance, value):
@@ -74,14 +77,8 @@ def _save(self, **kwargs): # signal, sender, instance):
7477
Save tags back to the database
7578
"""
7679
tags = self._get_instance_tag_cache(kwargs['instance'])
77-
Tag.objects.update_tags(kwargs['instance'], tags)
78-
79-
def _update(self, **kwargs): # signal, sender, instance):
80-
"""
81-
Update tag cache from TaggedItem objects.
82-
"""
83-
instance = kwargs['instance']
84-
self._update_instance_tag_cache(instance)
80+
if tags is not None:
81+
Tag.objects.update_tags(kwargs['instance'], tags)
8582

8683
def __delete__(self, instance):
8784
"""
@@ -101,15 +98,6 @@ def _set_instance_tag_cache(self, instance, tags):
10198
"""
10299
setattr(instance, '_%s_cache' % self.attname, tags)
103100

104-
def _update_instance_tag_cache(self, instance):
105-
"""
106-
Helper: update an instance's tag cache from actual Tags.
107-
"""
108-
# for an unsaved object, leave the default value alone
109-
if instance.pk is not None:
110-
tags = edit_string_for_tags(Tag.objects.get_for_object(instance))
111-
self._set_instance_tag_cache(instance, tags)
112-
113101
def get_internal_type(self):
114102
return 'CharField'
115103

tagging/tests/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from tagging import settings
1111
from tagging.forms import TagField
1212
from tagging.models import Tag, TaggedItem
13-
from tagging.tests.models import Article, Link, Perch, Parrot, FormTest, FormTestNull
13+
from tagging.tests.models import Article, Link, Perch, Parrot, FormTest
1414
from tagging.utils import calculate_cloud, edit_string_for_tags, get_tag_list, get_tag, parse_tag_input
1515
from tagging.utils import LINEAR
1616

0 commit comments

Comments
 (0)