fix #171339
authorsylvain.thenault@logilab.fr
Thu, 26 Feb 2009 12:30:16 +0100
changeset 967 aeeec5447eb0
parent 966 6dc63bfbdc1d
child 968 62c0489c1c92
fix #171339
server/rqlannotation.py
server/test/data/schema/relations.rel
server/test/unittest_rqlannotation.py
--- a/server/rqlannotation.py	Wed Feb 25 19:00:30 2009 +0100
+++ b/server/rqlannotation.py	Thu Feb 26 12:30:16 2009 +0100
@@ -260,7 +260,6 @@
                 has_text_query = True
         return has_text_query
 
-
     def is_ambiguous(self, var):
         # ignore has_text relation
         if len([rel for rel in var.stinfo['relations']
@@ -337,7 +336,7 @@
                 except KeyError:
                     # no relation to deambiguify
                     continue
-
+        
     def _debug_print(self):
         print 'varsols', dict((x, sorted(str(v) for v in values))
                                for x, values in self.varsols.iteritems())
@@ -375,8 +374,9 @@
             otheretypes = (other.uidtype,)
             deambiguifier = None
         if otheretypes is not None:
-            # unless types for variable are already non-ambigous, check
-            # if this relation has some type ambiguity
+            # to restrict, we must check that for all type in othertypes,
+            # possible types on the other end of the relation are matching
+            # variable's possible types
             rschema = self.rschema(rel.r_type)
             if onlhs:
                 rtypefunc = rschema.subjects
@@ -386,7 +386,8 @@
                 reltypes = frozenset(rtypefunc(otheretype))
                 if var.stinfo['possibletypes'] != reltypes:
                     break
-                self.restrict(var, reltypes)
+            else:
+                self.restrict(var, var.stinfo['possibletypes'])
                 self.deambification_map[var] = deambiguifier
                 return True
         return False
--- a/server/test/data/schema/relations.rel	Wed Feb 25 19:00:30 2009 +0100
+++ b/server/test/data/schema/relations.rel	Thu Feb 26 12:30:16 2009 +0100
@@ -43,3 +43,6 @@
 EPermission require_state State
 
 Note migrated_from Note
+
+Note attachment File
+Note attachment Image
--- a/server/test/unittest_rqlannotation.py	Wed Feb 25 19:00:30 2009 +0100
+++ b/server/test/unittest_rqlannotation.py	Thu Feb 26 12:30:16 2009 +0100
@@ -286,6 +286,12 @@
                               '(EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))')
         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
 
+    def test_nonregr_ambiguity(self):        
+        rqlst = self._prepare('Note N WHERE N attachment F')
+        # N may be an image as well, not invariant
+        self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
+        self.assertEquals(rqlst.defined_vars['F']._q_invariant, True)
+
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()