[PATCH seda V2] [views] Fix bad rql of vocabulary function

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Feb 23 11:26:02 CET 2017

# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1487766805 -3600
#      Wed Feb 22 13:33:25 2017 +0100
# Node ID 590fed554bd57cd66e44e7dc6e47b409316df1df
# Parent  84afe93e0ba1e42217ad0c792b1f5b8144e7728a
[views] Fix bad rql of vocabulary function

and add a test to avoid this in the future.

Along the way "properly" handle monkey-patching necessary to import some seda
views modules.

diff --git a/test/test_views.py b/test/test_views.py
--- a/test/test_views.py
+++ b/test/test_views.py
@@ -21,11 +21,11 @@ from six import text_type
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.web import INTERNAL_FIELD_VALUE
 from cubes.seda.xsd2yams import RULE_TYPES
-from cubes.seda.views import export, clone, mgmt_rules
+from cubes.seda.views import archiveunit, clone, export, mgmt_rules
 import testutils
 class ManagementRulesTC(CubicWebTC):
@@ -541,7 +541,28 @@ class SEDATreeTC(CubicWebTC):
+class FakeForm(object):
+    def __init__(self, req, edited_entity):
+        self._cw = req
+        self.edited_entity = edited_entity
+class ArchiveUnitVocabularyTC(CubicWebTC):
+    def test_do_ref_vocabulary(self):
+        with self.admin_access.web_request() as req:
+            transfer = req.cnx.create_entity('SEDAArchiveTransfer', title=u'Test')
+            bdo = testutils.create_data_object(transfer)
+            req.cnx.commit()
+            bdo.cw_clear_all_caches()
+            # actually expect a data object reference, but we want to test the query so any object
+            # linked to the container is fine
+            form = FakeForm(req, bdo)
+            self.assertEqual(archiveunit.do_ref_vocabulary(form, None),
+                             [(u'data object title', text_type(bdo.eid))])
 if __name__ == '__main__':
diff --git a/views/__init__.py b/views/__init__.py
--- a/views/__init__.py
+++ b/views/__init__.py
@@ -22,10 +22,14 @@ from cubicweb import tags, neg_role
 from cubicweb.utils import UStringIO
 from cubicweb.web import formfields as ff
 # XXX alias to avoid side effect: uicfg will become our uicfg submodule. Not necessary with 3.23?
 from cubicweb.web.views import uicfg as cwuicfg
+# XXX trigger monkey patches necessary to import this module, until we use a recent version of
+# lgc.registry supporting instantiation of rtags with explicit __module__ argument
+from ..seda import site_cubicweb  # noqa
 from ..xsd import XSDM_MAPPING
 from ..xsd2uicfg import FIRST_LEVEL_ETYPES
 from .widgets import SEDAMetaField
diff --git a/views/archiveunit.py b/views/archiveunit.py
--- a/views/archiveunit.py
+++ b/views/archiveunit.py
@@ -153,11 +153,11 @@ def do_ref_vocabulary(form, field):
     req = form._cw
     parent, container = parent_and_container(form.edited_entity)
     assert container is not None
     rset = req.execute('Any X, XUA ORDERBY XUA WHERE '
                        'X is IN(SEDABinaryDataObject, SEDAPhysicalDataObject), '
-                       ', X user_annotation XUAX container R, R eid %(root)s',
+                       'X user_annotation XUA, X container R, R eid %(root)s',
                        {'root': container.eid})
     return [(entity.dc_title(), str(entity.eid)) for entity in rset.entities()]
 for rtype in ('seda_data_object_reference_id', 'seda_target'):

More information about the saem-devel mailing list