[rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 27 Jan 2011 07:44:08 +0100
branchstable
changeset 6900 fcd4e6beec09
parent 6899 e592fb8ee27b
child 6901 118e78f6e4e4
[rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
rtags.py
--- a/rtags.py	Thu Jan 27 07:42:18 2011 +0100
+++ b/rtags.py	Thu Jan 27 07:44:08 2011 +0100
@@ -218,6 +218,9 @@
     def name(self):
         return self.__class__.name
 
+    # tag_subject_of / tag_object_of issue warning if '*' is not given as target
+    # type, while tag_relation handle it silently since it may be used during
+    # initialization
     def tag_subject_of(self, key, tag):
         subj, rtype, obj = key
         if obj != '*':
@@ -234,5 +237,14 @@
                          self.name, rtype, obj, subj, rtype, obj)
         super(NoTargetRelationTagsDict, self).tag_object_of(('*', rtype, obj), tag)
 
-
+    def tag_relation(self, key, tag):
+        if key[-1] == 'subject' and key[-2] != '*':
+            if isinstance(key, tuple):
+                key = list(key)
+            key[-2] = '*'
+        elif key[-1] == 'object' and key[0] != '*':
+            if isinstance(key, tuple):
+                key = list(key)
+            key[0] = '*'
+        super(NoTargetRelationTagsDict, self).tag_relation(key, tag)
 set_log_methods(RelationTags, logging.getLogger('cubicweb.rtags'))