From d969d5cec960ad5e093dde0a0dc69113f7eeff13 Mon Sep 17 00:00:00 2001
From: Ym <173550318+MaxonT@users.noreply.github.com>
Date: Tue, 24 Nov 2026 09:44:44 -0600
Subject: [PATCH] model: keep the first value list when several annotations
target one property
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
---
CHANGELOG.md | 3 +++
pyodata/v2/model.py | 7 +++++++
tests/test_model_v2.py | 47 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+)
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)