Skip to content

fix: remove invalid ParentConnection/ChildConnection from CrossAssociation BSON (#50)#105

Merged
ako merged 1 commit intomendixlabs:mainfrom
engalar:fix/cross-association-v2
Apr 6, 2026
Merged

fix: remove invalid ParentConnection/ChildConnection from CrossAssociation BSON (#50)#105
ako merged 1 commit intomendixlabs:mainfrom
engalar:fix/cross-association-v2

Conversation

@engalar
Copy link
Copy Markdown
Contributor

@engalar engalar commented Apr 6, 2026

Summary

  • CrossAssociation crash fix: Remove ParentConnection and ChildConnection fields from serializeCrossAssociation(). These properties only exist on DomainModels$Association, not DomainModels$CrossAssociation. Writing them causes Studio Pro to crash with System.InvalidOperationException: Sequence contains no matching element in MprProperty..ctor.
  • resolveMemberChange fallback: When no MPR reader is available, use dot-contains heuristic to distinguish associations (Module.Entity_Entity format) from attributes, instead of treating everything as an attribute.

Root Cause

The original serializeCrossAssociation was copy-pasted from serializeAssociation without removing Association-only properties. Mendix's type cache expects strict field alignment with the metamodel — extra fields trigger a crash.

Test plan

  • TestSerializeCrossAssociation_NoConnectionFields — verifies CrossAssociation omits Connection fields
  • TestSerializeAssociation_HasConnectionFields — verifies regular Association still includes them (regression guard)
  • TestResolveMemberChange_FallbackWithoutReader — verifies dot heuristic for attribute vs association
  • TDD red/green verified: reintroducing ParentConnection/ChildConnection causes test failure

Closes #50

…s#50)

Three bugs fixed:
1. Association members in CREATE/CHANGE OBJECT were misidentified as
   attributes (strings.Contains(".") heuristic replaced with domain
   model lookup via resolveMemberChange).
2. Entity types in DECLARE were treated as enumerations (bare qualified
   names now checked against domain model via isEntity callback).
3. CrossAssociation serialization included ParentConnection and
   ChildConnection fields that only exist on Association, causing
   Studio Pro to crash with InvalidOperationException.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

AI Code Review

What Looks Good

  • Bug fix correctness: The PR correctly identifies and fixes the root cause of Studio Pro crashes by removing invalid ParentConnection/ChildConnection fields from CrossAssociation serialization. These fields only exist on Association, not CrossAssociation, matching the Mendix metamodel.

  • Comprehensive test coverage:

    • Added TestSerializeCrossAssociation_NoConnectionFields verifying the fix
    • Added TestSerializeAssociation_HasConnectionFields as regression guard
    • Added TestResolveMemberChange_FallbackWithoutReader for the member change fallback logic
    • Tests validate both the presence/absence of fields correctly
  • Documentation improvement: Updated .claude/skills/debug-bson.md with a detailed diagnosis workflow for InvalidOperationException crashes, including Python scripts to identify extra properties - this is valuable for future debugging.

  • Appropriate fallback logic: The dot-contains heuristic in resolveMemberChange is a reasonable fallback when no MPR reader is available, distinguishing associations (Module.Entity_Entity) from attributes.

  • Clear commit scope: Both changes relate to issue fix: CREATE OBJECT writes associations as attributes, DECLARE treats entities as enumerations (CE1613) #50 (association handling) and are appropriately grouped together.

  • Code quality:

    • Explanatory comments clarify why fields were removed
    • Tests verify exhaustive field presence/absence
    • No duplication of existing functionality
    • Fixes are minimal and targeted

Recommendation

Approve. The PR correctly fixes a critical bug causing Studio Pro crashes, includes appropriate test coverage, improves documentation for similar future issues, and maintains code quality standards. The changes are focused, well-tested, and address the root cause without introducing regressions.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Copy link
Copy Markdown
Collaborator

@ako ako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Approve

Clean, well-scoped bug fix with good test coverage.

The fix is correct

CrossAssociation BSON: Root cause is clearly a copy-paste error — serializeCrossAssociation was cloned from serializeAssociation but kept ParentConnection and ChildConnection fields that don't exist on DomainModels$CrossAssociation. The Mendix type cache does a strict lookup and crashes on unknown fields. Removing them is the right fix.

resolveMemberChange fallback: The dot-contains heuristic (Module.Entity_Entity contains a dot → association, bare Name → attribute) is a reasonable fallback when no reader is available. Matches the convention that association names are always qualified while attribute names are bare.

Test quality is good

  • TestSerializeCrossAssociation_NoConnectionFields — checks both absence of invalid fields AND presence of all expected fields (exhaustive structural contract)
  • TestSerializeAssociation_HasConnectionFields — regression guard ensuring the fix didn't accidentally remove fields from the wrong function
  • TestResolveMemberChange_FallbackWithoutReader — covers both attribute (no dot) and association (with dot) paths

The debug-bson.md additions are valuable

The Python BSON diffing script is a solid diagnostic workflow for future type-mismatch crashes. The CE1613 section documenting both variants (association-as-attribute and entity-as-enumeration) is useful context.

@ako ako merged commit 1d7620f into mendixlabs:main Apr 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: CREATE OBJECT writes associations as attributes, DECLARE treats entities as enumerations (CE1613)

2 participants