don't try to remove relation if source has no entities
authorsylvain.thenault@logilab.fr
Mon, 12 Jan 2009 10:57:26 +0100
changeset 386 7af259b73c5b
parent 385 663f42a881ba
child 387 dbe9997ffc7e
don't try to remove relation if source has no entities
server/sources/__init__.py
--- a/server/sources/__init__.py	Fri Jan 09 19:38:47 2009 +0100
+++ b/server/sources/__init__.py	Mon Jan 12 10:57:26 2009 +0100
@@ -129,16 +129,15 @@
             if not key in self.PUBLIC_KEYS:
                 sourcedef.pop(key)
 
-    def cleanup_entities_info(self, session):
-        """cleanup system tables from information for entities coming from
-        this source. This should be called when a source is removed to
-        properly cleanup the database
+    def _cleanup_system_relations(self, session):
+        """remove relation in the system source referencing entities coming from
+        this source
         """
         cu = session.system_sql('SELECT eid FROM entities WHERE source=%(uri)s',
-                           {'uri': self.uri})
+                                {'uri': self.uri})
         myeids = ','.join(str(r[0]) for r in cu.fetchall())
-        # fti / entities tables cleanup
-        dbhelper = session.pool.source('system').dbhelper
+        if not myeids:
+            return
         # delete relations referencing one of those eids
         for rschema in self.schema.relations():
             if rschema.is_final() or rschema.type == 'identity':
@@ -164,7 +163,16 @@
                         rschema.type, myeids)
                     session.system_sql(sql)
                     break
+        
+    def cleanup_entities_info(self, session):
+        """cleanup system tables from information for entities coming from
+        this source. This should be called when a source is removed to
+        properly cleanup the database
+        """
+        self._cleanup_system_relations(session)
+        # fti / entities tables cleanup
         # sqlite doesn't support DELETE FROM xxx USING yyy
+        dbhelper = session.pool.source('system').dbhelper
         session.system_sql('DELETE FROM %s WHERE %s.%s IN (SELECT eid FROM '
                            'entities WHERE entities.source=%%(uri)s)'
                            % (dbhelper.fti_table, dbhelper.fti_table,