Skip to content

fix: association navigation expression missing target entity and extra spaces#165

Merged
ako merged 1 commit intomendixlabs:mainfrom
engalar:fix/issue-120-association-nav-expression
Apr 10, 2026
Merged

fix: association navigation expression missing target entity and extra spaces#165
ako merged 1 commit intomendixlabs:mainfrom
engalar:fix/issue-120-association-nav-expression

Conversation

@engalar
Copy link
Copy Markdown
Contributor

@engalar engalar commented Apr 9, 2026

Summary

Fixes #120 — association navigation expressions in microflows generated incorrect Mendix expressions causing CE0117.

  • Extra spaces: $Order / Module.Order_Customer / Name — parser misidentified path as division operators
  • Missing target entity: $Order/Module.Order_Customer/Name — Mendix requires $Order/Module.Order_Customer/Module.Customer/Name

Changes

  • Parser fix (visitor_microflow_expression.go): tryBuildAttributePath now handles IdentifierExpr and QualifiedNameExpr as path components, correctly parsing association navigation as AttributePathExpr
  • Builder fix (cmd_microflows_builder.go): Added exprToString()resolveAssociationPaths() pipeline on flowBuilder that auto-inserts the target entity after association segments using the existing lookupAssociation infrastructure
  • Call site updates (5 builder files): Replaced expressionToString() with fb.exprToString() for model-aware expression serialization
  • Tests (bugfix_test.go): 3 new test functions covering parsing, path resolution, and no-spaces serialization

Test plan

  • go build ./... — clean
  • go test ./... — 19/19 packages pass
  • New tests verify: $Order/Test.Order_Customer/Name parses as AttributePathExpr (not BinaryExpr)
  • New tests verify: expressionToString produces no extra spaces
  • Integration test with real MPR: create entities + association + microflow with association navigation, run mx check

…and extra spaces

Fixes two bugs in microflow expression generation (issue mendixlabs#120):

1. Parser: tryBuildAttributePath only handled LiteralExpr/VariableExpr as
   path components, so $Var/Module.Assoc/Attr was parsed as nested BinaryExpr
   with "/" operator, producing spaces: "$Var / Module.Assoc / Attr".
   Added IdentifierExpr and QualifiedNameExpr handling.

2. Builder: association navigation paths lacked the target entity qualifier
   required by Mendix (CE0117). Added resolveAssociationPaths on flowBuilder
   to auto-insert the target entity after association segments using the
   existing lookupAssociation infrastructure.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

AI Code Review

What Looks Good

This PR successfully fixes issue #120 regarding association navigation expressions in microflows. The changes are well-targeted and address both reported problems:

  1. Parser fix: Correctly identifies association paths as AttributePathExpr instead of misparsing them as division operations (BinaryExpr)
  2. Builder fix: Automatically inserts missing target entity qualifiers after association segments using existing lookupAssociation infrastructure
  3. Call site updates: Consistently uses the new fb.exprToString() method across all microflow expression generation points
  4. Test coverage: Adds three focused test functions verifying parsing, path resolution, and proper serialization

The implementation:

  • Leverages existing infrastructure (lookupAssociation) rather than creating new mechanisms
  • Makes minimal, focused changes across affected files
  • Preserves backward compatibility (paths with existing target entities remain unchanged)
  • Follows established patterns in the codebase
  • Includes appropriate nil-checks and error handling

Recommendation

Approve - This PR is ready for merging. It correctly fixes the reported bugs with appropriate test coverage and maintains consistency with the existing codebase architecture. The fix addresses both the parsing issue (extra spaces) and the semantic issue (missing target entity) in association navigation expressions.


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.

Two clear bugs solved with minimal, focused changes.

Bug 1: Extra spaces around /

Root cause: parser didn't recognize qualified names as path components, falling through to multiplicative operator rule and producing nested BinaryExpr{Op: "/"}. Fix in tryBuildAttributePath correctly handles IdentifierExpr and QualifiedNameExpr.

Bug 2: Missing target entity qualifier

Root cause: Mendix expressions require $Order/Mod.Assoc/Mod.Customer/Name but AST only stores [Mod.Assoc, Name]. Fix introduces fb.exprToString()resolveAssociationPaths() that walks the expression tree and inserts the target entity for each association segment.

What's good

  • Comprehensive call-site update — all 27+ uses of expressionToString in builder files switched to fb.exprToString
  • "Already resolved" heuristic prevents double-insertion when path is already qualified
  • Nil-reader fallback keeps tests/standalone use working
  • Recursive expression walking handles nested expressions (BinaryExpr, FunctionCallExpr, IfThenElseExpr, etc.)

Concerns

TestResolveAssociationPaths doesn't actually test resolution. It sets reader: nil which short-circuits the function, then only verifies the length stays the same. The assoc_then_attr case never verifies Test.Customer is actually inserted. A fake reader (or real MPR) would close this gap — the PR test plan already acknowledges this with the unchecked integration test box.

Inverse navigation may pick the wrong entity. lookupAssociation returns childEntityQN, but if someone navigates from the child side ($Customer/Mod.Order_Customer/...), the target should be parentEntityQN. Worth verifying whether lookupAssociation handles direction or if this is an unhandled edge case.

LGTM — the fix is correct for the common case. Recommend addressing the test gap and verifying inverse navigation in a follow-up.

@ako ako merged commit 48c1030 into mendixlabs:main Apr 10, 2026
1 of 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.

Association navigation expression: missing target entity and extra spaces

2 participants