You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ossie.apache.org by "ayushtkn (via GitHub)" <gi...@apache.org> on 2026/10/12 16:37:32 UTC

[PR] fix(core-spec): require a column in primary_key and in each unique key [ossie]

ayushtkn opened a new pull request, #574:
URL: https://github.com/apache/ossie/pull/574

   ## Summary
   
   `Dataset.primary_key` and `Dataset.unique_keys` accept an empty array, so a document
   can declare a key that names no column, and nothing rejects it:
   ```
                       before          after
   primary_key: []         PASSED          FAILED
   unique_keys: []         PASSED          FAILED
   unique_keys: [[]]       PASSED          FAILED
   primary_key: ['id']     PASSED          PASSED
   ```
   
   `Relationship.from_columns` and `to_columns` already carry `minItems: 1`, as do
   `Expression.dialects` and `SemanticModel.datasets` — these two properties were the
   only key or column arrays left loose.
   
   Three parts, because the schema alone is not enough:
   
   1. **Schema** — `minItems: 1` on `primary_key`, on `unique_keys`, and on each unique key
      definition, since a definition listing no column is the same mistake one level down.
   2. **SDK** — the models accepted `primary_key=[]` and would serialize a document the
      schema now refuses. `Field(min_length=1)` on a list is an item count, which is how
      the four existing `minItems` are already mirrored. It now rejects at
      `('primary_key',)` and, nested, at `('unique_keys', 0)`.
   3. **Parity test** — it read only `minLength`, so it could not have caught an
      unmirrored `minItems`, despite its comment claiming that role. It now reads both,
      covering all 13 constraints across the five mirrored nodes; the nested one is pinned
      separately, as the loop sees only the top level of each property.
   
   ### Nothing in the repository breaks
   
   I parsed every YAML, YML and JSON document in the tree: **0** declare an empty key
   array. The five CI validation flights still pass, as do `validation/test_validate.py`
   (53), `validation/tests/` (181) and `python/` (174, was 173).
   
   ### Deliberately out of scope
   
   - `primary_key: ['']` still passes. That is a separate `minLength`-on-items gap which
     affects all four column arrays equally; tightening it here alone would create a fresh
     asymmetry.
   
   ## Related Issues
   
   <!-- Link any related GitHub issues: Closes #123, Fixes #456 -->
   
   ## Checklist
   
   ### Specification
   - [ ] Spec changes are included in `core-spec/` and follow the existing structure
   - [ ] Spec changes have been discussed on the mailing list or in a linked issue
   - [ ] Breaking changes to the spec are clearly called out in the summary
   
   ### Ontology
   - [ ] Ontology changes in `ontology/` are consistent with spec changes
   - [ ] New or modified terms are defined and documented
   
   ### Converters
   - [ ] Converter logic in `converters/` is updated to reflect spec or ontology changes
   - [ ] New converters include tests under the converter's test directory
   - [ ] If adding a new converter, `.github/labeler.yml` is updated with the new path
   
   ### Validation
   - [ ] Validation rules in `validation/` are updated if the spec changed
   - [ ] New validation cases are covered by tests
   
   ### Documentation
   - [ ] `docs/` is updated to reflect any user-facing changes
   - [ ] New features or behaviors are documented with examples where appropriate
   - [ ] `CONTRIBUTING.md` is updated if the contribution process changed
   
   ### Examples
   - [ ] `examples/` are added or updated for any new spec constructs or converter support
   
   ### Tests
   - [ ] All existing tests pass (`pytest` / CI green)
   - [ ] New functionality is covered by tests
   
   ### Compliance
   - [ ] ASF license headers are present on all new source files
   - [ ] No third-party dependencies are added without PMC/IPMC approval
   - [ ] If third-party source code is vendored/copied (not just declared as a dependency), `NOTICE` and/or `LICENSE` have been updated per [ASF policy](https://infra.apache.org/licensing-howto.html)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(core-spec): require a column in primary_key and in each unique key [ossie]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre merged PR #574:
URL: https://github.com/apache/ossie/pull/574


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(core-spec): require a column in primary_key and in each unique key [ossie]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #574:
URL: https://github.com/apache/ossie/pull/574#discussion_r4250437604


##########
python/tests/test_models.py:
##########
@@ -538,16 +538,36 @@ def test_identifier_min_length_matches_core_schema() -> None:
     checked = 0
     for node, model in _CONSTRAINED_NODES.items():
         for prop, prop_schema in schema["$defs"][node]["properties"].items():
-            expected = prop_schema.get("minLength")
-            if expected is None:
-                continue
-            assert _model_min_length(model, prop) == expected, (
-                f"{node}.{prop} requires minLength {expected} in the schema"
-            )
-            checked += 1
+            # Pydantic spells both as `min_length`: on a str it is a character count,
+            # on a list an item count, so one comparison covers minLength and minItems.
+            for keyword in ("minLength", "minItems"):
+                expected = prop_schema.get(keyword)
+                if expected is None:
+                    continue
+                assert _model_min_length(model, prop) == expected, (
+                    f"{node}.{prop} requires {keyword} {expected} in the schema"
+                )
+                checked += 1
 
     # Guards against the loop silently checking nothing if the schema moves.
-    assert checked == 8
+    assert checked == 13

Review Comment:
   This exact-count assertion will require manual updates whenever any mirrored `minLength`/`minItems` constraint is added/removed in the schema, which can create noisy failures unrelated to parity correctness. Consider asserting a safer invariant (e.g., `checked > 0` plus pinning specific expected properties/keywords), or deriving the expected count by scanning the schema for those keywords within `_CONSTRAINED_NODES`.



##########
python/tests/test_models.py:
##########
@@ -538,16 +538,36 @@ def test_identifier_min_length_matches_core_schema() -> None:
     checked = 0
     for node, model in _CONSTRAINED_NODES.items():
         for prop, prop_schema in schema["$defs"][node]["properties"].items():
-            expected = prop_schema.get("minLength")
-            if expected is None:
-                continue
-            assert _model_min_length(model, prop) == expected, (
-                f"{node}.{prop} requires minLength {expected} in the schema"
-            )
-            checked += 1
+            # Pydantic spells both as `min_length`: on a str it is a character count,
+            # on a list an item count, so one comparison covers minLength and minItems.
+            for keyword in ("minLength", "minItems"):
+                expected = prop_schema.get(keyword)
+                if expected is None:
+                    continue
+                assert _model_min_length(model, prop) == expected, (
+                    f"{node}.{prop} requires {keyword} {expected} in the schema"
+                )
+                checked += 1
 
     # Guards against the loop silently checking nothing if the schema moves.
-    assert checked == 8
+    assert checked == 13
+
+
+def test_unique_key_definitions_may_not_be_empty() -> None:
+    """The constraint nests: each definition in `unique_keys` needs a column too.
+
+    The parity test above reads only the top level of each property, so the inner
+    `minItems` is pinned here.
+    """
+    schema_path = Path(__file__).parents[2] / "core-spec" / "ossie-schema.json"
+    schema = json.loads(schema_path.read_text())
+    unique_keys = schema["$defs"]["Dataset"]["properties"]["unique_keys"]
+
+    assert unique_keys["items"]["minItems"] == 1
+
+    with pytest.raises(ValidationError) as error:
+        OssieDataset(name="orders", source="db.s.orders", unique_keys=[[]])
+    assert error.value.errors()[0]["loc"] == ("unique_keys", 0)

Review Comment:
   Indexing `errors()[0]` makes the test brittle because Pydantic does not guarantee error ordering across versions/changes. Make the assertion order-independent by checking that *any* returned error has `loc == (\"unique_keys\", 0)`.



##########
python/tests/test_models.py:
##########
@@ -538,16 +538,36 @@ def test_identifier_min_length_matches_core_schema() -> None:
     checked = 0
     for node, model in _CONSTRAINED_NODES.items():
         for prop, prop_schema in schema["$defs"][node]["properties"].items():
-            expected = prop_schema.get("minLength")
-            if expected is None:
-                continue
-            assert _model_min_length(model, prop) == expected, (
-                f"{node}.{prop} requires minLength {expected} in the schema"
-            )
-            checked += 1
+            # Pydantic spells both as `min_length`: on a str it is a character count,
+            # on a list an item count, so one comparison covers minLength and minItems.
+            for keyword in ("minLength", "minItems"):
+                expected = prop_schema.get(keyword)
+                if expected is None:
+                    continue
+                assert _model_min_length(model, prop) == expected, (
+                    f"{node}.{prop} requires {keyword} {expected} in the schema"
+                )
+                checked += 1
 
     # Guards against the loop silently checking nothing if the schema moves.
-    assert checked == 8
+    assert checked == 13
+
+
+def test_unique_key_definitions_may_not_be_empty() -> None:
+    """The constraint nests: each definition in `unique_keys` needs a column too.
+
+    The parity test above reads only the top level of each property, so the inner
+    `minItems` is pinned here.
+    """
+    schema_path = Path(__file__).parents[2] / "core-spec" / "ossie-schema.json"
+    schema = json.loads(schema_path.read_text())
+    unique_keys = schema["$defs"]["Dataset"]["properties"]["unique_keys"]

Review Comment:
   `read_text()` relies on the platform default encoding, which can make this test less portable. Prefer `schema_path.read_text(encoding=\"utf-8\")` to ensure consistent behavior across environments.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org