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>
changeset1965eda264bd
branchdefault
phasepublic
hiddenno
parent revision#8c2612f53bf6 fix wrong type analysis with 'NOT identity' (closes #80799)
child revision#33ac0225993e [node] fix add_type_restriction (closes #81817)
files modified by this revision
nodes.py
test/unittest_nodes.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1319795718 -7200
# Fri Oct 28 11:55:18 2011 +0200
# Node ID 1965eda264bd152da47e49553b929a6fcc6c5f91
# Parent 8c2612f53bf66217c2765aed8cfb549f3d4411e3
fix Referencable.get_type crash when no solution given and 'is IN(ET1, ET2..) is used. Closes #81865

diff --git a/nodes.py b/nodes.py
@@ -954,11 +954,13 @@
1      def get_type(self, solution=None, kwargs=None):
2          """return entity type of this object, 'Any' if not found"""
3          if solution:
4              return solution[self.name]
5          if self.stinfo['typerel']:
6 -            return str(self.stinfo['typerel'].children[1].children[0].value)
7 +            rhs = self.stinfo['typerel'].children[1].children[0]
8 +            if isinstance(rhs, Constant):
9 +                return str(rhs.value)
10          schema = self.schema
11          if schema is not None:
12              for rel in self.stinfo['rhsrelations']:
13                  try:
14                      lhstype = rel.children[0].get_type(solution, kwargs)
diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py
@@ -506,10 +506,16 @@
15          tree = parse(u"Any X WHERE X creation_date NOW")
16          self.assertEqual(tree.as_string(), 'Any X WHERE X creation_date NOW')
17          tree = parse(u"Any X WHERE X creation_date TODAY")
18          self.assertEqual(tree.as_string(), 'Any X WHERE X creation_date TODAY')
19 
20 +
21 +    def test_get_type_is_in(self):
22 +        tree = sparse("Any X WHERE X is IN (Person, Company)")
23 +        select = tree.children[0]
24 +        self.assertEqual(select.defined_vars['X'].get_type(), 'Any')
25 +
26      # sub-queries tests #######################################################
27 
28      def test_subq_colalias_compat(self):
29          tree = sparse('Any X ORDERBY N WHERE X creation_date <NOW WITH X,N BEING ('
30                       '(Any X,N WHERE X firstname N) UNION (Any X,N WHERE X name N, X is Company))')
@@ -602,7 +608,8 @@
31          for varref in varrefs:
32              self.assertIsInstance(varref, nodes.VariableRef)
33          self.assertEqual(sorted(x.name for x in varrefs),
34                            ['X', 'X', 'X', 'Y', 'Y'])
35 
36 +
37  if __name__ == '__main__':
38      unittest_main()