Repository navigation
fix(concerto-core): reject array identifying fields - #1611
Siddharth-Dangi wants to merge 1 commit into
Conversation
|
Thank you for the pull request, and for the clear write-up of how an array identifying field loads and then fails at runtime. That part looks like a real gap, and I could not find an existing issue or pull request for it. Concerto maintainers have been asked to review; I can't say when, but this will be in their queue. One thing that will help review: the change also covers several other areas, namely default values on array, scalar and relationship properties, enum declaration rules, Also, please check that your commit is signed off (DCO) as the repository requires. Drafted by an Accord Project agent, reviewed by a maintainer. |
|
Thanks @mira-accord-project! Glad to hear the array identifying field gap is confirmed. (Also confirmed that the DCO check has passed green). I completely agree with the suggestion: to make this as fast and clean as possible to review and merge, I have a trimmed branch ready that isolates solely the array identifying field check and its inheritance tests with zero overlap with #1606 or #1608. Happy to push that focused version right away, or wait for the maintainers' steer as you suggested. Thank you! |
869fa94 to
7c9b7d3
Compare
|
Hi @mira-accord-project & maintainers — I have updated this PR to isolate strictly the array identifying field check and its test suite:
Ready for maintainer review. Thank you! |
7c9b7d3 to
89970bf
Compare
There was a problem hiding this comment.
Thank you for this, Siddharth, and for narrowing it down to the array identifier check. The change is small and sits in the right place in ClassDeclaration.validate(). It runs after the String and optional checks, so scalar string arrays and identifiers inherited from a super type are both caught. The error wording matches the neighbouring "cannot be optional" message. The new tests cover direct, scalar, inherited, participant and three-level cases, and each one reaches the new throw. I found nothing to change in the code. What remains is process rather than code: the CI workflows are still waiting for a first-time-contributor approval, so there is no test run at this commit yet, and a maintainer review is still needed. Please be aware that models with an array identifier that previously loaded will now be rejected at load time. They already failed when instantiating or deserialising, so this looks like the intended outcome, but maintainers may want to note it in the release notes.
No problems found.
Automated review by Mira, an Accord Project agent, at 89970bf. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.
Identifying fields must uniquely identify a resource instance with a scalar
value. Previously, ClassDeclaration.validate() only verified that identifying
fields were strings (or scalar strings) and not optional, but did not check
if the property was declared as an array (idField.isArray()).
Consequently, models declaring array identifying fields (e.g. `o String[] names`
or scalar string arrays, directly or through inheritance) loaded successfully at
model load time, only to fail at runtime during instantiation or serialization.
This change checks `idField.isArray()` in `ClassDeclaration.validate()` and
throws an `IllegalModelException('Identifying fields cannot be arrays.')`.
Signed-off-by: Siddharth-Dangi <mr.siddharthdangi@gmail.com>
89970bf to
b3e0b7b
Compare
Summary
An identifying field in Concerto must uniquely identify a resource instance with a scalar value. At model load time,
ClassDeclaration.validate()verified that identifying fields were strings (or scalar strings) and not optional, but did not check whether the property was declared as an array (idField.isArray()).Consequently, models declaring array identifying fields (e.g.
asset Person identified by names { o String[] names }or with scalar string arrays, directly or through inheritance) loaded without errors intoModelManager, but failed at runtime during resource instantiation or deserialization:Factory.newResource('test@1.0.0', 'Person', 'alice')sets'alice'onto an array field, failing downstream withModel violation: The field "names" has a value of ""alice"". Expected type of value: "String[]".Factory.newResource(..., ['alice'])throwsError: Invalid or missing identifier for Type "Person".Serializer.fromJSON()throwsError: Invalid or missing identifier for Type "Person".Per maintainer feedback on simplifying and expediting review, this pull request isolates solely the array identifying field check, eliminating any overlap with other open PRs.
Changes
packages/concerto-core/src/introspect/classdeclaration.ts:if (idField.isArray()) throw new IllegalModelException('Identifying fields cannot be arrays.', this.modelFile, this.ast.location);withinClassDeclaration.validate().packages/concerto-core/test/data/parser/assetdeclaration.arrayid.cto:packages/concerto-core/test/introspect/assetdeclaration.js:loadAssetDeclarationthrowsIllegalModelExceptionon array identifying field.packages/concerto-core/test/introspect/classdeclaration.js:asset Person identified by names { o String[] names })concept Person identified by ssnArray { o SSN[] ssnArray })abstract asset Base { o String[] ids } asset Child identified by ids extends Base)participant Member identified by memberIds { o String[] memberIds })Testing
packages/concerto-core: 1,386 passing unit tests, 0 failures.test:esm: All 10 ESM smoke checks pass.npm run licchk: 100% compliant.npm run lint: Clean, 0 errors.Signed-off-by: Siddharth-Dangi mr.siddharthdangi@gmail.com