fix(mappings): an unauthored import range is All, not First - #192
Merged
Conversation
`import from mapping M.IMM($json)` — no range keyword — built a document the
Mendix runtime refuses:
MicroflowException: key not found: Path(QName(None,),None,)
at ...integration.importer.mapping.MappingCache.storeValueMappingElement
The model is valid, so nothing static caught it: mxcli check, mx check (0
errors) and mxbuild all pass. It fails only when the activity runs, and the
repo had no runtime coverage of import mappings — every existing test stopped
at mx check.
The Range and the result variable's cardinality are separate axes (mendixlabs#881), but
an unauthored range set neither pointer, so ForceSingleOccurrence and
ConstantRange.SingleObject both fell back to SingleObject — true for an
object-rooted mapping. That is Studio Pro's First ("take one of a list"), not a
single-object import. Studio Pro writes both flags false and expresses "one
object" solely through VariableType=ObjectType.
`all`, `first` and limit/offset each set the pointers explicitly, so only the
bare form was affected — the form the shipped examples use
(06-rest-client-examples.mdl:1506, :1541). `first` is unchanged.
Measured against a Studio Pro-authored app on 11.13.0: in one boot, over the
same mapping and the same JSON, `... all` imported and the bare form threw;
with the fix both import. The cross-test is what located it — an mxcli
microflow calling Studio Pro's own mapping fails too, which rules out the
mapping document, the JSON structure and the entity.
Also updates TestImportRange_UnauthoredKeepsTheOldInference, which asserted the
faulty fallback. It passed only because it exercised the list-rooted case,
where the fallback is false either way.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dp1syGhH8yr7Hve2wwjzqg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
import from mapping M.IMM($json)— the bare form, with no range keyword — built a document the Mendix runtime refuses:Reported as "import mapping documents fail at runtime — JSON path resolution is broken in mxcli's serialization." The mapping document turned out to be fine; the defect is in the activity.
Root cause
The Range and the result variable's cardinality are separate axes (mendixlabs#881). But an unauthored range set neither pointer, so
ForceSingleOccurrenceandConstantRange.SingleObjectboth fell back toSingleObject—truefor an object-rooted mapping. That is Studio Pro's First ("take one of a list"), which is a different activity.Studio Pro writes both flags false for a plain single-object import and expresses "one object" solely through
VariableType=ObjectType:VariableTypeForceSingleOccurrenceConstantRange.SingleObjectObjectTypefalsefalseObjectTypetruetrueall,firstand limit/offset each set their pointers explicitly, so only the bare form was affected — the form the shipped examples use (06-rest-client-examples.mdl:1506,:1541).firstis deliberately unchanged.Why nothing caught it
The model is valid.
mxcli check,mx check(0 errors) and mxbuild all pass — the document is well-formed, it just means something else. It fails only when the activity runs, and the repo had no runtime coverage of import mappings at all: every existing mapping test stopped atmx check. This is exactly the gap.claude/skills/verify-in-runtime.mdexists for.How it was located
A Studio Pro-authored app on the same Mendix version (11.13.0) with the same JSON snippet, run under
mxcli run --local, then cross the variables:... allvs bare, same mapping, same bootallimports, bare throwsThe last row is the discriminator; the third is what ruled out the mapping document, the JSON structure and the entity. An "isolation" where both artifacts are mxcli's isolates nothing — two earlier conclusions were wrong for exactly that reason, including one that blamed the mapping document.
Four document-level differences vs Studio Pro were each applied and booted, individually and combined, and none fixed it:
int32vsint64on 14 numerics, rootMinOccurs0 vs 1, missingMessageDefinition2, blankedOriginalValue. BSON key order (Studio Pro writes alphabetically) was also tested and eliminated. Those divergences are real but out of scope here.Testing
TestImportRange_UnauthoredObjectRootedWritesAllNotFirstfails pre-fix withrange SingleObject = trueandForceSingleOccurrence = <nil>— causation shown from both directions, since the runtime independently threw the reported exception.allboth import in the same boot.TestImportRange_UnauthoredKeepsTheOldInferenceasserted the faulty fallback (RangeSingleObject == nil) and is updated. It passed only because it exercised the list-rooted case, where the fallback isfalseeither way and therefore harmless — renamed to...KeepsTheCardinalityInference, keeping the part that is still true.go test ./...green,make check-mdl352 PASS / 0 FAIL, gofmt clean.mdl-examples/bug-tests/import-mapping-single-object-runtime.mdl(bare form plus theallandfirstcontrols). Symptom row appended tofix-issue.md.Follow-ups, not in this PR
show references to <import mapping>reports none even when a microflow uses it..test.mdlanywhere exercisesimport from mapping; adding one undermxcli test --localis what would have caught this.🤖 Generated with Claude Code
https://claude.ai/code/session_01Dp1syGhH8yr7Hve2wwjzqg
Generated by Claude Code