warn and drop rtags not in schema, this may be intentional; drop possibility to not specify value for bool rtags tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 12 May 2009 15:56:00 +0200
branchtls-sprint
changeset 1740 2292ae32c98f
parent 1739 78b0819162a8
child 1741 fe5266f0f88c
warn and drop rtags not in schema, this may be intentional; drop possibility to not specify value for bool rtags
rtags.py
--- a/rtags.py	Tue May 12 11:56:12 2009 +0200
+++ b/rtags.py	Tue May 12 15:56:00 2009 +0200
@@ -6,6 +6,10 @@
 """
 __docformat__ = "restructuredtext en"
 
+import logging
+
+from logilab.common.logging_ext import set_log_methods
+
 
 class RelationTags(object):
     """a tag store for full relation definitions :
@@ -46,12 +50,12 @@
 
     def init(self, schema):
         # XXX check existing keys against schema
-        for rtype, tagged, stype, otype in self._tagdefs:
-            assert rtype in schema
-            if stype != '*':
-                assert stype in schema
-            if otype != '*':
-                assert otype in schema
+        for rtype, tagged, stype, otype in self._tagdefs.keys():
+            for ertype in (stype, rtype, otype):
+                if ertype != '*' and not ertype in schema:
+                    self.warning('removing rtag for %s, undefined in schema',
+                                 ertype)
+                    self.del_rtag(stype, rtype, otype, tagged)
         if self._initfunc is not None:
             for eschema in schema.entities():
                 for rschema, tschemas, role in eschema.relation_definitions(True):
@@ -129,11 +133,5 @@
 class RelationTagsBool(RelationTags):
     _allowed_values = frozenset((True, False))
 
-    def tag_subject_of(self, key, tag=True):
-        super(RelationTagsBool, self).tag_subject_of(key, tag)
 
-    def tag_object_of(self, key, tag=True):
-        super(RelationTagsBool, self).tag_object_of(key, tag)
-
-    def tag_attribute(self, key, tag=True):
-        super(RelationTagsBool, self).tag_attribute(key, tag)
+set_log_methods(RelationTags, logging.getLogger('cubicweb.rtags'))