don't fail if vobjects reference an unexistant class tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 10 Mar 2009 19:36:16 +0100
branchtls-sprint
changeset 1037 1f3fae8d82b2
parent 1036 593df4919845
child 1038 2e8a3e556351
don't fail if vobjects reference an unexistant class
cwvreg.py
selectors.py
--- a/cwvreg.py	Tue Mar 10 19:35:38 2009 +0100
+++ b/cwvreg.py	Tue Mar 10 19:36:16 2009 +0100
@@ -102,6 +102,10 @@
 
     def register(self, obj, **kwargs):
         if kwargs.get('registryname', obj.__registry__) == 'etypes':
+            if obj.id != 'Any' and not obj.id in self.schema:
+                self.error('don\'t register %s, %s type not defined in the schema',
+                           obj, obj.id)
+                return
             kwargs['clear'] = True
         super(CubicWebRegistry, self).register(obj, **kwargs)
         # XXX bw compat
@@ -126,7 +130,7 @@
                         interfaces.update(expand_parent_classes(iface))
                     interfaces.update(expand_parent_classes(cls))
             for obj, ifaces in self._needs_iface.items():
-                ifaces = frozenset(isinstance(iface, basestring) and self.etype_class(iface) or iface
+                ifaces = frozenset(isinstance(iface, basestring) and iface in self.schema and self.etype_class(iface) or iface
                                    for iface in ifaces)
                 if not ifaces & interfaces:
                     self.debug('kicking vobject %s (unsupported interface)', obj)
--- a/selectors.py	Tue Mar 10 19:35:38 2009 +0100
+++ b/selectors.py	Tue Mar 10 19:36:16 2009 +0100
@@ -522,7 +522,10 @@
         for iface in self.expected_ifaces:
             if isinstance(iface, basestring):
                 # entity type
-                iface = eclass.vreg.etype_class(iface)
+                try:
+                    iface = eclass.vreg.etype_class(iface)
+                except KeyError:
+                    continue # entity type not in the schema
             if implements_iface(eclass, iface):
                 if getattr(iface, '__registry__', None) == 'etypes':
                     # adjust score if the interface is an entity class