fix solutions computation crash with some query using sub-queries (closes #37423)

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset7b8e124f230c
branchstable
phasepublic
hiddenno
parent revision#5a8ae1ed1c84 Added tag rql-debian-version-0.26.4-1 for changeset 88b739e85c61
child revision#7050cbae30a3 0.26.5
files modified by this revision
ChangeLog
analyze.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1280745126 -7200
# Mon Aug 02 12:32:06 2010 +0200
# Branch stable
# Node ID 7b8e124f230c6bc0e43e0f93e8f312ed0a592b9f
# Parent 5a8ae1ed1c84006e5e6c628e163e3d68af1164c2
fix solutions computation crash with some query using sub-queries (closes #37423)

diff --git a/ChangeLog b/ChangeLog
@@ -1,8 +1,11 @@
1  ChangeLog for RQL
2  =================
3 
4 +	--
5 +   * fix solutions computation crash with some query using sub-queries (closes #37423)
6 +
7  2010-07-28  --  0.26.4
8      * fix re-annotation pb: some stinfo keys were not properly reinitialized
9        which may cause pb later (at sql generation time for instance)
10 
11 
diff --git a/analyze.py b/analyze.py
@@ -375,12 +375,12 @@
12              for etype in self._uid_node_types(term):
13                  for targettypes in get_target_types(etype):
14                      alltypes.add(targettypes)
15          else:
16              alltypes = get_target_types()
17 -
18 -        constraints.var_has_types( var, [ str(t) for t in alltypes] )
19 +        domain = constraints.domains[var]
20 +        constraints.var_has_types( var, [str(t) for t in alltypes if t in domain] )
21 
22      def visit(self, node, uid_func_mapping=None, kwargs=None, debug=False):
23          # FIXME: not thread safe
24          self.debug = debug
25          if uid_func_mapping is not None:
@@ -507,22 +507,30 @@
26                  for v in rhs.iget_nodes(nodes.VariableRef):
27                      if v.name == lhsvar:
28                          samevar = True
29                      else:
30                          rhsvars.append(v.name)
31 +            lhsdomain = constraints.domains[lhsvar]
32              if rhsvars:
33                  s2 = '=='.join(rhsvars)
34 +                # filter according to domain necessary for column aliases
35 +                rhsdomain = constraints.domains[rhsvars[0]]
36                  res = []
37                  for fromtype, totypes in rschema.associations():
38 -                    res.append( [ ( [lhsvar], [str(fromtype)]), (rhsvars, [ str(t) for t in totypes]) ] )
39 +                    if not fromtype in lhsdomain:
40 +                        continue
41 +                    ptypes = [str(t) for t in totypes if t in rhsdomain]
42 +                    res.append( [ ( [lhsvar], [str(fromtype)]), (rhsvars, ptypes) ] )
43                  constraints.or_and( res )
44              else:
45 -                constraints.var_has_types( lhsvar, [ str(subj) for subj in rschema.subjects()] )
46 +                ptypes = [str(subj) for subj in rschema.subjects()
47 +                          if subj in lhsdomain]
48 +                constraints.var_has_types( lhsvar, ptypes )
49              if samevar:
50                  res = []
51                  for fromtype, totypes in rschema.associations():
52 -                    if not fromtype in totypes:
53 +                    if not (fromtype in totypes and fromtype in lhsdomain):
54                          continue
55                      res.append(str(fromtype))
56                  constraints.var_has_types( lhsvar, res )
57          return True
58