fix Referencable.get_type crash when no solution given and 'is IN(ET1, ET2..) is used. Closes #81865
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 28 Oct 2011 11:55:18 +0200
changeset 672 1965eda264bd
parent 671 8c2612f53bf6
child 673 33ac0225993e
fix Referencable.get_type crash when no solution given and 'is IN(ET1, ET2..) is used. Closes #81865
nodes.py
test/unittest_nodes.py
--- a/nodes.py	Tue Oct 25 17:56:34 2011 +0200
+++ b/nodes.py	Fri Oct 28 11:55:18 2011 +0200
@@ -956,7 +956,9 @@
         if solution:
             return solution[self.name]
         if self.stinfo['typerel']:
-            return str(self.stinfo['typerel'].children[1].children[0].value)
+            rhs = self.stinfo['typerel'].children[1].children[0]
+            if isinstance(rhs, Constant):
+                return str(rhs.value)
         schema = self.schema
         if schema is not None:
             for rel in self.stinfo['rhsrelations']:
--- a/test/unittest_nodes.py	Tue Oct 25 17:56:34 2011 +0200
+++ b/test/unittest_nodes.py	Fri Oct 28 11:55:18 2011 +0200
@@ -508,6 +508,12 @@
         tree = parse(u"Any X WHERE X creation_date TODAY")
         self.assertEqual(tree.as_string(), 'Any X WHERE X creation_date TODAY')
 
+
+    def test_get_type_is_in(self):
+        tree = sparse("Any X WHERE X is IN (Person, Company)")
+        select = tree.children[0]
+        self.assertEqual(select.defined_vars['X'].get_type(), 'Any')
+
     # sub-queries tests #######################################################
 
     def test_subq_colalias_compat(self):
@@ -604,5 +610,6 @@
         self.assertEqual(sorted(x.name for x in varrefs),
                           ['X', 'X', 'X', 'Y', 'Y'])
 
+
 if __name__ == '__main__':
     unittest_main()