[PATCH 1 of 3 seda] [profile gen] Be more resilient about supported concept's languages

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 30 17:43:17 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490884727 -7200
#      Thu Mar 30 16:38:47 2017 +0200
# Node ID 92eafd2e3edaefc5dfaeacb5c726b5f21c0b6ce9
# Parent  0ae7957cf9e319c325f80032787e9567806a1727
[profile gen] Be more resilient about supported concept's languages

For now, we don't want export 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 (eg internal seda vocabulary or open vocabulary
such as keyword reference), but for now, let's add 'fr' in the expected language
list and fallback to any language if none has been found so the export doesn't
fail.

Related to extranet #15934212

diff --git a/cubicweb_seda/entities/profile_generation.py b/cubicweb_seda/entities/profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py
+++ b/cubicweb_seda/entities/profile_generation.py
@@ -88,17 +88,16 @@ def _concept_value(concept, language):
       'seda-02')
     """
     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):
     """Return a value usable as ID/IDREF for the given eid."""
     return 'id' + text_type(eid)
diff --git a/test/test_profile_generation.py b/test/test_profile_generation.py
--- a/test/test_profile_generation.py
+++ b/test/test_profile_generation.py
@@ -576,11 +576,12 @@ class SEDAExportFuncTCMixIn(object):
 
     def setup_database(self):
         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',
                               seda_message_digest_algorithm_code_list_version_from=transfer,
                               seda_message_digest_algorithm_code_list_version_to=scheme)
@@ -703,10 +704,13 @@ class OldSEDAExportMixin(object):
                     ('seda_final_action', 'SEDAAppraisalRule', u'detruire'),
             ]:
                 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 &&',
                               simplified_profile=True)
 


More information about the saem-devel mailing list