backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 08 Jun 2011 17:08:00 +0200
changeset 7473 a164fdf3de5d
parent 7471 bf9443f8725f (current diff)
parent 7472 9833c09460f1 (diff)
child 7474 7dc405ad7bf3
backport stable
cwvreg.py
schema.py
server/checkintegrity.py
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- a/cwvreg.py	Tue Jun 07 16:07:06 2011 +0200
+++ b/cwvreg.py	Wed Jun 08 17:08:00 2011 +0200
@@ -758,7 +758,7 @@
                           sitewide=False):
         """register a given property"""
         properties = self['propertydefs']
-        assert type in YAMS_TO_PY
+        assert type in YAMS_TO_PY, 'unknown type %s' % type
         properties[key] = {'type': type, 'vocabulary': vocabulary,
                            'default': default, 'help': help,
                            'sitewide': sitewide}
--- a/schema.py	Tue Jun 07 16:07:06 2011 +0200
+++ b/schema.py	Wed Jun 08 17:08:00 2011 +0200
@@ -378,11 +378,27 @@
     def add_subject_relation(self, rschema):
         """register the relation schema as possible subject relation"""
         super(CubicWebEntitySchema, self).add_subject_relation(rschema)
-        self._update_has_text()
+        if rschema.final:
+            if self.rdef(rschema).get('fulltextindexed'):
+                self._update_has_text()
+        elif rschema.fulltext_container:
+            self._update_has_text()
+
+    def add_object_relation(self, rschema):
+        """register the relation schema as possible object relation"""
+        super(CubicWebEntitySchema, self).add_object_relation(rschema)
+        if rschema.fulltext_container:
+            self._update_has_text()
 
     def del_subject_relation(self, rtype):
         super(CubicWebEntitySchema, self).del_subject_relation(rtype)
-        self._update_has_text(True)
+        if 'has_text' in self.subjrels:
+            self._update_has_text(deletion=True)
+
+    def del_object_relation(self, rtype):
+        super(CubicWebEntitySchema, self).del_object_relation(rtype)
+        if 'has_text' in self.subjrels:
+            self._update_has_text(deletion=True)
 
     def _update_has_text(self, deletion=False):
         may_need_has_text, has_has_text = False, False
--- a/server/checkintegrity.py	Tue Jun 07 16:07:06 2011 +0200
+++ b/server/checkintegrity.py	Wed Jun 08 17:08:00 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -30,7 +30,7 @@
 
 from logilab.common.shellutils import ProgressBar
 
-from cubicweb.schema import PURE_VIRTUAL_RTYPES
+from cubicweb.schema import PURE_VIRTUAL_RTYPES, VIRTUAL_RTYPES
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.server.session import security_enabled
 
--- a/server/sources/rql2sql.py	Tue Jun 07 16:07:06 2011 +0200
+++ b/server/sources/rql2sql.py	Wed Jun 08 17:08:00 2011 +0200
@@ -1258,11 +1258,16 @@
         unification (eg X attr1 A, Y attr2 A). In case of selection,
         nothing to do here.
         """
-        for var in rhs_vars:
+        for vref in rhs_vars:
+            var = vref.variable
             if var.name in self._varmap:
                 # ensure table is added
-                self._var_info(var.variable)
-            principal = var.variable.stinfo.get('principal')
+                self._var_info(var)
+            if isinstance(var, ColumnAlias):
+                # force sql generation whatever the computed principal
+                principal = 1
+            else:
+                principal = var.stinfo.get('principal')
             if principal is not None and principal is not relation:
                 # we have to generate unification expression
                 lhssql = self._inlined_var_sql(relation.children[0].variable,
--- a/server/test/unittest_rql2sql.py	Tue Jun 07 16:07:06 2011 +0200
+++ b/server/test/unittest_rql2sql.py	Wed Jun 08 17:08:00 2011 +0200
@@ -1465,6 +1465,12 @@
 WHERE ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_X.cw_eid AND rel_owned_by0.eid_to=1)) OR (((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by2, cw_Affaire AS _D LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=_D.cw_eid) LEFT OUTER JOIN cw_Note AS _B ON (rel_concerne1.eid_to=_B.cw_eid) WHERE rel_owned_by2.eid_from=_B.cw_eid AND rel_owned_by2.eid_to=1 AND _X.cw_eid=_D.cw_eid)) OR (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by4, cw_Affaire AS _F LEFT OUTER JOIN concerne_relation AS rel_concerne3 ON (rel_concerne3.eid_from=_F.cw_eid) LEFT OUTER JOIN cw_Societe AS _E ON (rel_concerne3.eid_to=_E.cw_eid) WHERE rel_owned_by4.eid_from=_E.cw_eid AND rel_owned_by4.eid_to=1 AND _X.cw_eid=_F.cw_eid))))))) AS _T0, cw_CWEType AS _ET, is_relation AS rel_is0
 WHERE rel_is0.eid_from=_T0.C0 AND rel_is0.eid_to=_ET.cw_eid
 GROUP BY _ET.cw_name'''),
+
+            ('Any A WHERE A ordernum O, A is CWAttribute WITH O BEING (Any MAX(O) WHERE A ordernum O, A is CWAttribute)',
+             '''SELECT _A.cw_eid
+FROM (SELECT MAX(_A.cw_ordernum) AS C0
+FROM cw_CWAttribute AS _A) AS _T0, cw_CWAttribute AS _A
+WHERE _A.cw_ordernum=_T0.C0'''),
             )):
             yield t