diff --git a/CHANGELOG.md b/CHANGELOG.md index f90c9f7..fda130a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed + +- model: several value list annotations on the same property no longer mark the schema invalid; the first one is kept and the rest are logged as ignored (#142) ## [1.12.2] diff --git a/pyodata/v2/model.py b/pyodata/v2/model.py index 14a9756..637dbbd 100644 --- a/pyodata/v2/model.py +++ b/pyodata/v2/model.py @@ -1439,6 +1439,13 @@ def from_etree(schema_nodes, config: Config): raise RuntimeError(f'Target Property {annotation.proprty_name} ' f'of {vh_type} as defined in {annotation} does not exist') + if target_proprty.value_helper is not None: + # OData allows several annotations of the same term on one target; + # PyOData keeps only one value helper per property, so keep the first. + modlog().warning('Ignoring additional value list %s, %s already has %s', + annotation, target_proprty, target_proprty.value_helper) + continue + annotation.proprty = target_proprty target_proprty.value_helper = annotation except (RuntimeError, PyODataModelError) as ex: diff --git a/tests/test_model_v2.py b/tests/test_model_v2.py index 87c669b..b1e6392 100644 --- a/tests/test_model_v2.py +++ b/tests/test_model_v2.py @@ -1751,3 +1751,50 @@ def test_invalid_xml(xml_builder_factory): with pytest.raises(PyODataParserError) as e_info: MetadataBuilder(xml).build() assert str(e_info.value) == 'Metadata document syntax error' + + +@patch('logging.Logger.warning') +def test_annot_v_l_duplicate_target(mock_warning, xml_builder_factory): + """Several value list annotations of one property must not invalidate the schema""" + + vl = """ + + + + + + + + + + + + + + + + + + """ + + xml_builder = xml_builder_factory() + xml_builder.add_schema( + 'DUP_VL', + """ + + + + + + + + + """ + vl.format(label='First') + vl.format(label='Second') + ) + + schema = MetadataBuilder(xml_builder.serialize()).build() + + assert schema.is_valid + value_helper = schema.entity_type('Dict').proprty('Value').value_helper + assert value_helper.label == 'First' + assert any('Ignoring additional value list' in str(call.args[0]) for call in mock_warning.call_args_list)