You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ossie.apache.org by jb...@apache.org on 2026/10/12 11:04:01 UTC
(ossie) branch main updated: fix(python): give the non-finite diagnostic its missing verb (#565)
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ossie.git
The following commit(s) were added to refs/heads/main by this push:
new e49a0f0c fix(python): give the non-finite diagnostic its missing verb (#565)
e49a0f0c is described below
commit e49a0f0ca2336669ba22662853eba63bff3ce8d1
Author: Ayush Saxena <ay...@apache.org>
AuthorDate: Mon Oct 12 16:33:54 2026 +0530
fix(python): give the non-finite diagnostic its missing verb (#565)
The message was assembled as `f"property {reason}: {paths}"`, which read as a
sentence only for the null case. For a non-finite number it came out as "property
not a number JSON can represent, so it cannot round-trip: path".
Each reason now carries the subject, so it is a whole clause on its own and the
template adds nothing. The null wording is unchanged; the non-finite one gains
"holds".
The existing tests match on "set to null" and "cannot round-trip", both of which
appeared before that move, so they passed either way and left the change
uncovered. Two tests now assert the complete text: reverting the composition fails
the non-finite one. The null assertion passes in both states, because that message
is unchanged by design, and guards the other direction instead, where a template
that regained its prefix would read "property property set to null".
---
python/src/ossie/models.py | 7 ++++---
python/tests/test_serialization.py | 29 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/python/src/ossie/models.py b/python/src/ossie/models.py
index ffac09bf..31d1fa69 100644
--- a/python/src/ossie/models.py
+++ b/python/src/ossie/models.py
@@ -29,8 +29,9 @@ _AI_CONTEXT_FIELDS = frozenset({"instructions", "synonyms", "examples"})
#: Paths listed in a diagnostic before the rest are counted instead.
_MAX_REPORTED = 20
-_NULL = "set to null, which the schema does not allow; omit it instead"
-_NON_FINITE = "not a number JSON can represent, so it cannot round-trip"
+# Each reads as a whole clause, so one can be followed by the paths it applies to.
+_NULL = "property set to null, which the schema does not allow; omit it instead"
+_NON_FINITE = "property holds a number JSON cannot represent, so it cannot round-trip"
def _cyclic(path: str) -> ValueError:
@@ -378,7 +379,7 @@ class OssieDocument(OssieSemanticModel):
listed = ", ".join(paths[:_MAX_REPORTED])
if len(paths) > _MAX_REPORTED:
listed += f", and {len(paths) - _MAX_REPORTED} more"
- raise ValueError(f"property {reason}: {listed}")
+ raise ValueError(f"{reason}: {listed}")
if isinstance(data, dict) and "version" in cls.model_fields and "version" not in data:
# The field carries a default so Python construction needs no version, but
# the schema lists it as required, so a document without one is invalid.
diff --git a/python/tests/test_serialization.py b/python/tests/test_serialization.py
index 275e9888..62d8e219 100644
--- a/python/tests/test_serialization.py
+++ b/python/tests/test_serialization.py
@@ -646,3 +646,32 @@ def test_free_form_ai_context_content_is_passed_through() -> None:
"numbered": {"1": "one"},
}
+
+def test_the_null_diagnostic_reads_as_a_sentence(document_data: dict) -> None:
+ """Assert the whole message, not a fragment of it.
+
+ The reason and the template have to agree on who the subject is, and a substring
+ match passes either way round, so only the full text covers that.
+ """
+ document_data["description"] = None
+
+ with pytest.raises(ValueError) as error:
+ OssieDocument.from_ossie_yaml(yaml.safe_dump(document_data))
+
+ assert str(error.value) == (
+ "property set to null, which the schema does not allow; omit it instead: description"
+ )
+
+
+def test_the_non_finite_diagnostic_reads_as_a_sentence(document_data: dict) -> None:
+ """The case the subject was missing from; see the test above."""
+ document_data["datasets"][0]["ai_context"] = {"score": float("nan")}
+
+ with pytest.raises(ValueError) as error:
+ OssieDocument.from_ossie_yaml(yaml.safe_dump(document_data))
+
+ assert str(error.value) == (
+ "property holds a number JSON cannot represent, so it cannot round-trip: "
+ "datasets[0].ai_context.score"
+ )
+