[profile gen] Be more resilient about supported concept's languages
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 30 Mar 2017 16:38:47 +0200
changeset 2563 455ce14bb7bf
parent 2555 0ae7957cf9e3
child 2564 dd0fa3ba2760
[profile gen] Be more resilient about supported concept's languages Export used to chose concept value by searching for label with the following language code: 1. version specific (seda-2, seda-1 or seda-02) 2. seda 3. en and crash if no matching label was found. But it seems we don't want it to crash because we use some concept which has e.g. only a concept in 'fr' language code. At some point we may want to improve this, depending on the relation (internal seda vocabulary vs open vocabulary such as keyword reference), but for now, let's add 'fr' to the expected language list and fallback to any language if none has been found so the export doesn't fail. Related to extranet #15934212
cubicweb_seda/entities/profile_generation.py
test/test_profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py	Thu Mar 30 13:53:01 2017 +0200
+++ b/cubicweb_seda/entities/profile_generation.py	Thu Mar 30 16:38:47 2017 +0200
@@ -90,13 +90,12 @@
     assert language in ('seda-2', 'seda-1', 'seda-02')
     if concept is None:
         return None
-    for code in (language, 'seda', 'en'):
+    for code in (language, 'seda', 'en', 'fr'):
         try:
             return concept.labels[code]
         except KeyError:
             continue
-    raise RuntimeError('Concept %s has no preferred label in one of "%s", "seda" or "en" language'
-                       % (concept.eid, language))
+    return concept.label()
 
 
 def eid2xmlid(eid):
--- a/test/test_profile_generation.py	Thu Mar 30 13:53:01 2017 +0200
+++ b/test/test_profile_generation.py	Thu Mar 30 16:38:47 2017 +0200
@@ -578,7 +578,8 @@
         with self.admin_access.client_cnx() as cnx:
             create = cnx.create_entity
             scheme = create('ConceptScheme', title=u'Keyword Types')
-            some_concept = scheme.add_concept(label=u'md5')
+            # ensure we're able to export concept with unexpected language code
+            some_concept = scheme.add_concept(label=u'md5', language_code=u'de')
 
             transfer = create('SEDAArchiveTransfer', title=u'test profile')
             cnx.create_entity('SEDAMessageDigestAlgorithmCodeListVersion',
@@ -705,6 +706,9 @@
                 scheme = testutils.scheme_for_type(cnx, rtype, etype, value)
                 concepts[value] = scheme.reverse_in_scheme[0]
 
+            # ensure we're able to export concept with unexpected language code
+            concepts['md5'].preferred_label[0].cw_set(language_code=u'de')
+
             agent = testutils.create_authority_record(cnx, u'bob')
 
             transfer = create('SEDAArchiveTransfer', title=u'my profile title &&',