[profile gen] Systematically turn IDREF into NCName in SEDA 2.0 RNG export
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 18 May 2017 23:01:43 +0200
changeset 2638 67558c0fc5ee
parent 2636 7319f0d205c4
child 2639 5cda167cef43
[profile gen] Systematically turn IDREF into NCName in SEDA 2.0 RNG export RNG doesn't handle ID/IDREF as XSD: it doesn't handle having some tag's *content* of such type, as it is the case in SEDA 2 ObjectReferenceId element. See https://www.oasis-open.org/committees/relax-ng/compatibility.html#id for details. To fix this, 'downgrade' ID into NCName. This was already done when some data object was referenced, but it should actually be done systematically. Closes #17078970
cubicweb_seda/entities/profile_generation.py
test/test_profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py	Wed May 10 15:36:34 2017 +0200
+++ b/cubicweb_seda/entities/profile_generation.py	Thu May 18 23:01:43 2017 +0200
@@ -67,6 +67,8 @@
         if isinstance(content_type, set):
             content_types = sorted(content_type)
         else:
+            if content_type == 'IDREF':
+                content_type = 'NCName'
             content_types = (content_type,)
     else:
         content_types = ()
@@ -547,7 +549,7 @@
         if fixed_value is not None:
             if _internal_reference(value):
                 profile_element.attrib[self.qname('a:defaultValue')] = fixed_value
-                self.element('rng:data', profile_element, {'type': 'NCName'})
+                self.element('rng:data', profile_element, {'type': xstype})
             else:
                 if (len(profile_element)
                         and profile_element[-1].tag == '{http://relaxng.org/ns/structure/1.0}data'):
--- a/test/test_profile_generation.py	Wed May 10 15:36:34 2017 +0200
+++ b/test/test_profile_generation.py	Thu May 18 23:01:43 2017 +0200
@@ -669,7 +669,8 @@
         references = self.xpath(root, '//rng:element[@a:defaultValue="{}"]'.format(xmlid))
         self.assertEqual(len(references), 1)
         self.assertEqual(references[0].attrib['name'], 'DataObjectReferenceId')
-        self.assertEqual(references[0][0].attrib['type'], 'NCName')
+        for reference_id in self.xpath(root, '//rng:element[@name="DataObjectReferenceId"]'):
+            self.assertEqual(reference_id[0].attrib['type'], 'NCName')
         # ensure optional id are properly reinjected
         references = self.xpath(root,
                                 '//rng:element[@name="Keyword"]/rng:optional'