[querier] we should not insert None but skip the line when some unknown eid is detected (closes #1892491) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 02 Aug 2011 17:37:55 +0200
branchstable
changeset 7730 8d0edec31aaf
parent 7729 5f89f11143bc
child 7731 48e78934a4e2
[querier] we should not insert None but skip the line when some unknown eid is detected (closes #1892491)
server/session.py
server/test/unittest_session.py
--- a/server/session.py	Tue Aug 02 17:31:06 2011 +0200
+++ b/server/session.py	Tue Aug 02 17:37:55 2011 +0200
@@ -1180,7 +1180,8 @@
     def _build_descr(self, result, basedescription, todetermine):
         description = []
         etype_from_eid = self.describe
-        for row in result:
+        todel = []
+        for i, row in enumerate(result):
             row_descr = basedescription[:]
             for index, isfinal in todetermine:
                 value = row[index]
@@ -1194,10 +1195,14 @@
                     try:
                         row_descr[index] = etype_from_eid(value)[0]
                     except UnknownEid:
-                        self.critical('wrong eid %s in repository, you should '
-                                      'db-check the database' % value)
-                        row_descr[index] = row[index] = None
-            description.append(tuple(row_descr))
+                        self.error('wrong eid %s in repository, you should '
+                                   'db-check the database' % value)
+                        todel.append(i)
+                        break
+            else:
+                description.append(tuple(row_descr))
+        for i in reversed(todel):
+            del result[i]
         return description
 
     # deprecated ###############################################################
--- a/server/test/unittest_session.py	Tue Aug 02 17:31:06 2011 +0200
+++ b/server/test/unittest_session.py	Tue Aug 02 17:37:55 2011 +0200
@@ -78,5 +78,15 @@
         self.assertEqual(session._tx_data, {})
         self.assertEqual(session.cnxset, None)
 
+    def test_build_descr(self):
+        rset = self.execute('(Any U,L WHERE U login L) UNION (Any G,N WHERE G name N, G is CWGroup)')
+        orig_length = len(rset)
+        rset.rows[0][0] = 9999999
+        description = self.session.build_description(rset.syntax_tree(), None, rset.rows)
+        self.assertEqual(len(description), orig_length - 1)
+        self.assertEqual(len(rset.rows), orig_length - 1)
+        self.failIf(rset.rows[0][0] == 9999999)
+
+
 if __name__ == '__main__':
     unittest_main()