--- a/hooks/syncschema.py Thu May 20 20:50:00 2010 +0200
+++ b/hooks/syncschema.py Thu May 20 20:50:03 2010 +0200
@@ -34,7 +34,8 @@
from cubicweb import ValidationError
from cubicweb.selectors import implements
-from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CONSTRAINTS, display_name
+from cubicweb.schema import (META_RTYPES, VIRTUAL_RTYPES, CONSTRAINTS,
+ ETYPE_NAME_MAP, display_name)
from cubicweb.server import hook, schemaserial as ss
from cubicweb.server.sqlutils import SQL_PREFIX
@@ -815,9 +816,10 @@
if name in CORE_ETYPES:
raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
# delete every entities of this type
- self._cw.execute('DELETE %s X' % name)
+ if not name in ETYPE_NAME_MAP:
+ self._cw.execute('DELETE %s X' % name)
+ MemSchemaCWETypeDel(self._cw, name)
DropTable(self._cw, table=SQL_PREFIX + name)
- MemSchemaCWETypeDel(self._cw, name)
class AfterDelCWETypeHook(DelCWETypeHook):
@@ -982,7 +984,11 @@
def __call__(self):
session = self._cw
- rdef = session.vreg.schema.schema_by_eid(self.eidfrom)
+ try:
+ rdef = session.vreg.schema.schema_by_eid(self.eidfrom)
+ except KeyError:
+ self.critical('cant get schema rdef associated to %s', self.eidfrom)
+ return
subjschema, rschema, objschema = rdef.as_triple()
pendings = session.transaction_data.get('pendingeids', ())
pendingrdefs = session.transaction_data.setdefault('pendingrdefs', set())
@@ -1003,7 +1009,6 @@
# we have to update physical schema systematically for final and inlined
# relations, but only if it's the last instance for this relation type
# for other relations
-
if (rschema.final or rschema.inlined):
rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, '
'R eid %%(x)s, X from_entity E, E name %%(name)s'