Repository navigation
fix(concerto-core): prevent TypeNotFoundException when serializing map with DateTime values - #1547
sadSanta-07 wants to merge 1 commit into
Conversation
…p with DateTime values Signed-off-by: pechkas <iffcogc34@gmail.com>
There was a problem hiding this comment.
Thank you for tracking this down, and for adding a regression test. The bug is real: a Dayjs map value reaches modelManager.getType('DateTime') and throws, and routing primitive map values through convertToJSON is the right idea. To make this mergeable: rebase onto the current main and keep its relationship handling in visitMapDeclaration, cover map values that are a scalar extending DateTime, and trim the whitespace-only edits so the diff shows just the fix. CI is also failing and the branch has conflicts, so please re-run it after the rebase.
Nothing blocking; some suggestions below. Findings: 2 should-fix, 3 nit.
- nit · hygiene: Pull request #1548 addresses the same issue (#1546) in the same function and also covers scalars,
nullvalues andutcOffset. Maintainers will want to merge only one, so it would help to say in the description how this PR differs, or to agree with the other author which one to take.
Automated review by Mira, an Accord Project agent, at 9e008f2. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.
| : modelFile.getFullyQualifiedTypeName(mapDeclaration.getValue().getType()); | ||
| const decl = modelFile.getModelManager().getType(valueType); | ||
| if (!Util.isNull(value) && typeof value === 'object') { | ||
| const mapValueDecl = mapDeclaration.getValue(); |
There was a problem hiding this comment.
should-fix · correctness
This branch is based on an older main. On main, visitMapDeclaration starts with if (mapDeclaration.getValue().isRelationship()) { value = this.processRelationship(...) } else if (typeof value === 'object') { ... }, and this diff has no such branch. If the merge conflict is resolved by taking this version, maps whose values are relationships would stop serializing correctly. Please rebase onto main, keep the relationship branch first, and put the primitive/DateTime handling alongside the existing object branch.
| : modelFile.getFullyQualifiedTypeName(mapDeclaration.getValue().getType()); | ||
| const decl = modelFile.getModelManager().getType(valueType); | ||
| if (!Util.isNull(value) && typeof value === 'object') { | ||
| const mapValueDecl = mapDeclaration.getValue(); |
There was a problem hiding this comment.
should-fix · correctness
Only a map whose value type is the primitive DateTime is fixed. For a map whose value is a scalar that extends DateTime, mapValueDecl.getType() returns the scalar's name, ModelUtil.isPrimitiveType is false, and a Dayjs object still goes down the modelManager.getType(...) / decl.accept(this, ...) path. A ScalarDeclaration does not appear to be handled by visit (it has no isTypeScalar/isField), so that case looks likely to still throw. I could not run it, so please confirm with a test. Resolve the scalar's underlying primitive type before choosing the branch (for example from the scalar declaration's getType()), and add a test for a scalar ... extends DateTime map value.
| { | ||
| return obj; | ||
| } | ||
| case 'DateTime': |
There was a problem hiding this comment.
nit · conventions
The diff includes formatting-only changes unrelated to the fix: spacing after if in visit, visitMapDeclaration and visitClassDeclaration, and the switch in convertToJSON re-indented so case sits inside switch. They add noise and make the real change harder to review, and they add to the conflicts. Please revert the formatting-only hunks and keep the diff to the change in visitMapDeclaration.
|
|
||
| }); | ||
|
|
||
| describe('#visitMapDeclaration', () => { |
There was a problem hiding this comment.
nit · tests
The new test covers only Map<String, DateTime> with the default UTC offset. The null value guard and a non-zero utcOffset are changed in the code but not tested, and neither is the scalar case above. The test also calls require('../../src/serializer') inside the test body; moving it to the top of the file matches the rest of the suite. Please add small tests for a null map value, a non-zero offset, and a DateTime scalar value.
|
Thanks for the PR, @sadSanta-07. Serializing One thing to know: open PR #1548 changes the same code in Drafted by an Accord Project agent, reviewed by a maintainer. |
|
This PR is stale because it has been open with no activity. Remove the stale label or comment to keep it active. Only items with maintainer engagement are auto-closed. |
Fixes #1546.
Root Cause:
In
visitMapDeclaration,typeof value === 'object'capturesdayjsinstances (which representDateTimeat runtime) as well asnull. This bypassed primitive handling and forced a lookup for"DateTime"in theModelManager, throwing aTypeNotFoundException.Solution:
!Util.isNull(value).ModelUtil.isPrimitiveType(...). If the map value is a primitive (likeDateTime), it delegates directly tothis.convertToJSON(), bypassing the custom class resolution.jsongenerator.jsmimicking the exact crash scenario to ensure it never regresses.All tests are passing locally.