Skip to content

fix: preserve indirect sort entity references#370

Open
hjotha wants to merge 3 commits intomendixlabs:mainfrom
hjotha:submit/retrieve-sort-indirect-entity-ref
Open

fix: preserve indirect sort entity references#370
hjotha wants to merge 3 commits intomendixlabs:mainfrom
hjotha:submit/retrieve-sort-indirect-entity-ref

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 27, 2026

Summary

  • preserve DomainModels$IndirectEntityRef steps on microflow sort items
  • infer one-hop association sort references while building retrieve statements
  • keep rejecting unrelated qualified sort attributes when no association path is known

Closes #367. Part of #332.

Validation

  • make build
  • make lint-go
  • make test

hjothamendix and others added 2 commits April 30, 2026 09:51
Symptom: retrieve statements sorted by an attribute on a related entity either fail builder validation or roundtrip without the DomainModels$IndirectEntityRef needed by Studio Pro.

Root cause: SortItem only stored the final attribute name. The parser dropped EntityRef steps from BSON, the writer could not emit them, and the builder rejected qualified sort attributes whose entity differed from the retrieve source.

Fix: carry EntityRefStep metadata on microflow sort items, parse and serialize indirect entity refs, and infer a one-hop association step when building retrieves sorted through a known domain association.

Tests: add SDK parser/writer coverage for indirect entity refs and builder coverage for sorting a retrieve through a related entity. make build, make lint-go, and make test pass.
Adds an MDL script under mdl-examples/bug-tests/ exercising a
retrieve sorted by an attribute on a related entity via a one-hop
association. After exec, `mx check` reports 0 errors and the
describe output preserves the qualified
`Module.Entity.Attribute` form, confirming the IndirectEntityRef
step survives roundtrip.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@hjotha hjotha force-pushed the submit/retrieve-sort-indirect-entity-ref branch from 3debc54 to 878a169 Compare April 30, 2026 07:52
@github-actions
Copy link
Copy Markdown

AI Code Review

Critical Issues

None found.

Moderate Issues

None found.

Minor Issues

  • The inferSortEntityRefSteps function in mdl/executor/cmd_microflows_builder_actions.go uses strings.SplitN(sourceEntityQN, ".", 2) to extract the module name. While this works for qualified names like Module.Entity, it assumes the qualified name has exactly two parts. This is safe given the context (entity qualified names from the model always follow Module.Entity format), but could be made more robust by using strings.Split and checking length. However, this is a minor concern given the controlled input.
  • The entityQualifiedNameFromAttribute helper function returns an empty string for attribute paths with fewer than 3 parts (e.g., Entity.Attribute). While this correctly handles the expected Module.Entity.Attribute format, it would also return empty for malformed paths like Attribute or Entity.Attribute.Attribute. This is acceptable as the function is only called after validating the attribute path contains dots (in the caller), but adding a comment about the expected format would improve clarity.

What Looks Good

  • The PR correctly addresses bug Preserve indirect entity references in retrieve sort items #367 by preserving DomainModels$IndirectEntityRef steps in retrieve sort items through:
    • Proper BSON serialization/deserialization of EntityRefSteps in sort items
    • Logical inference of one-hop association paths during AST-to-executor translation
    • Maintenance of existing validation for unrelated qualified attributes
  • Test coverage is excellent:
    • New bug test in mdl-examples/bug-tests/ reproduces the issue and verifies the fix
    • Unit tests in mdl/executor/ validate the builder behavior
    • Parser/writer tests in sdk/mpr/ confirm BSON roundtrip preservation
  • Changes are tightly scoped to the specific issue without touching unrelated areas
  • Code follows existing patterns in the microflow builder and SDK
  • Backend abstraction is properly maintained (executor uses ctx.Backend.* calls)
  • Error handling is preserved - unrelated attributes still produce appropriate errors

Recommendation

Approve the PR. The changes correctly fix the reported bug with comprehensive test coverage and maintain all architectural constraints. Minor code clarity improvements are suggested but not blocking.


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

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.

Preserve indirect entity references in retrieve sort items

2 participants