Skip to content

Fix DESCRIBE PAGE / ALTER PAGE column name mismatch for DataGrid2 columns (#116)#298

Open
yscraft wants to merge 2 commits intomendixlabs:mainfrom
yscraft:fix/issue-116-describe-alter-page-column-names
Open

Fix DESCRIBE PAGE / ALTER PAGE column name mismatch for DataGrid2 columns (#116)#298
yscraft wants to merge 2 commits intomendixlabs:mainfrom
yscraft:fix/issue-116-describe-alter-page-column-names

Conversation

@yscraft
Copy link
Copy Markdown

@yscraft yscraft commented Apr 24, 2026

Summary

Fixes #116.

DESCRIBE PAGE and ALTER PAGE derived DataGrid2 column names independently with two bugs that caused mismatches:

  • Wrong TextTemplate path (H1): deriveColumnNameBson read TextTemplate → Items directly, skipping the intermediate Template document. DESCRIBE correctly traverses TextTemplate → Template → Items. Result: caption-only columns always fell back to col1, col2, … in ALTER regardless of what DESCRIBE showed.
  • Sanitization divergence (H2): sanitizeColumnName didn't trim leading/trailing underscores and didn't fall through to col{N} for all-special-char captions, unlike deriveColumnName on the DESCRIBE side.

Changes

mdl/executor/cmd_alter_page.go

  • deriveColumnNameBson — traverse TextTemplate → Template → Items (nil-fallback for edge cases); gate sanitizeColumnName result so empty string falls through to col{N}
  • sanitizeColumnName — rewritten to match deriveColumnName exactly: strings.Map + strings.TrimFunc, returns "" when result is all underscores

mdl/executor/alter_page_test.go

  • 5 regression tests: attribute binding, caption fallback (the broken path), all-special-char caption → col{N}, index fallback, sanitization trimming

Test plan

  • go test ./mdl/executor/... -run TestDeriveColumnNameBson|TestSanitizeColumnName — all 5 pass
  • go test ./mdl/executor/... — full suite passes, no regressions

🤖 Generated with Claude Code

deriveColumnNameBson skipped the intermediate TextTemplate.Template
document when reading DataGrid2 column headers, so caption-only columns
always fell back to col{N} instead of the name DESCRIBE PAGE shows.
sanitizeColumnName also diverged from deriveColumnName on edge cases
(leading/trailing underscores, all-special-char captions).

Fix: traverse TextTemplate → Template → Items (with a nil fallback for
older BSON), rewrite sanitizeColumnName to match deriveColumnName
exactly (returns "" for all-special-char input so caller uses col{N}),
and add 5 regression tests covering attribute binding, caption fallback,
all-special-char caption, index fallback, and sanitization trimming.
@github-actions
Copy link
Copy Markdown

AI Code Review

Critical Issues

None

Moderate Issues

None

Minor Issues

None

What Looks Good

  • The PR correctly identifies and fixes two distinct bugs causing DESCRIBE/ALTER PAGE column name mismatches for DataGrid2:
    1. Wrong TextTemplate path: Fixed by adding the missing Template traversal step (TextTemplate → Template → Items) with appropriate nil fallback
    2. Sanitization divergence: Rewrote sanitizeColumnName to exactly match the DESCRIBE side's behavior (using strings.Map + strings.TrimFunc, returning empty string for all-underscore results)
  • Test coverage is excellent: 5 new regression tests cover all fix scenarios (attribute binding, caption fallback, index fallback, underscore trimming, all-special-char fallback)
  • Changes are minimal and focused - only modified the two buggy functions in cmd_alter_page.go and added corresponding tests
  • Code is well-documented with clear comments explaining the fix and fallback logic
  • Maintains backward compatibility while ensuring DESCRIBE/ALTER consistency
  • No changes to MDL syntax, grammar, or pipeline wiring (appropriate for a bug fix in existing functionality)

Recommendation

Approve the PR. The fix correctly resolves issue #116 with appropriate test coverage and minimal, focused changes. No further action needed.


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

@yscraft
Copy link
Copy Markdown
Author

yscraft commented Apr 24, 2026

Hey @ako, this PR fixes issue #116 — DataGrid2 column name mismatch between DESCRIBE PAGE and ALTER PAGE. Could you take a look when you get a chance?

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.

Code Review — PR #298

Overview: Fixes a DESCRIBE/ALTER mismatch for DataGrid2 column names. Two independent bugs correctly identified and fixed. The unit tests are solid. One design concern before merging.


What's good

  • Root cause analysis is correct — the PR description accurately explains both bugs (H1: wrong BSON traversal path, H2: sanitization divergence)
  • sanitizeColumnName rewrite is a direct copy of the DESCRIBE-side logic — guaranteed to match
  • The empty-string gate (if name := sanitizeColumnName(caption); name != "") correctly enables the col{N} fallback for all-special-char captions
  • 5 unit tests cover attribute binding, caption path, all-special-char fallback, index fallback, and sanitization trimming

One concern: the template = tmpl fallback may reintroduce a divergence

The H1 fix adds a defensive fallback:

template := dGetDoc(tmpl, "Template")
if template == nil {
    template = tmpl // fallback: some versions store Items directly
}

The DESCRIBE side (extractTextContent in cmd_pages_describe_output.go) does not have this fallback:

template, ok := content["Template"].(map[string]any)
if !ok {
    return ""  // no Template → no caption
}

If Template is nil, DESCRIBE returns "" and falls through to col{N}. ALTER with the fallback would instead read Items from tmpl directly and derive a name — producing a different result than DESCRIBE.

The stated goal is for ALTER and DESCRIBE to agree. The safest fix is to match DESCRIBE exactly and drop the fallback:

template := dGetDoc(tmpl, "Template")
if template == nil {
    break // no Template → no caption, match DESCRIBE behaviour
}

There's also no test for the fallback path, which suggests there's no known Mendix version that actually uses it.


Missing: bug-test MDL script

Per the PR checklist in CLAUDE.md:

Every bug fix should include an MDL test script in mdl-examples/bug-tests/ that reproduces the issue, so the fix can be verified in Studio Pro if applicable.

mdl-examples/bug-tests/116-datagrid2-column-name-mismatch.mdl is missing. A script that creates a DataGrid2 with a caption-only column and verifies DESCRIBE PAGE roundtrips the column name correctly would cover this.


Minor

  • makePropTypeID / propKey helpers in the test file are clear and well-named
  • TestDeriveColumnNameBson_CaptionFallback directly exercises the previously broken path — good regression anchor

Summary: Approve after dropping the template = tmpl fallback (match DESCRIBE exactly) and adding a bug-tests/116-*.mdl script. The core fix is correct.

…t script

Drop the `template = tmpl` fallback in deriveColumnNameBson — if Template
is nil, DESCRIBE returns "" and falls to col{N}, so ALTER must do the same.
The fallback had no test coverage and would have reintroduced a divergence.

Add mdl-examples/bug-tests/116-datagrid2-column-name-mismatch.mdl per the
PR checklist: covers attribute-bound, caption-only, and all-special-char
column name roundtrip.
@yscraft
Copy link
Copy Markdown
Author

yscraft commented May 1, 2026

Thanks for the thorough review, @ako. Both points addressed:

1. Dropped the template = tmpl fallback
If Template is nil, deriveColumnNameBson now matches extractTextContent on the DESCRIBE side exactly — no caption, falls through to col{N}. There was no test covering the fallback path and no known Mendix version that needs it.

2. Added mdl-examples/bug-tests/116-datagrid2-column-name-mismatch.mdl
Covers three column scenarios: attribute-bound (regression guard), caption-only (the previously broken H1 path), and all-special-char caption → col{N} (H2). Instructions included for manual Studio Pro verification.

All 5 unit tests still pass.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

AI Code Review

Critical Issues

None found.

Moderate Issues

None found.

Minor Issues

None found.

What Looks Good

  • Bug fix accuracy: The PR correctly addresses both issues mentioned in DESCRIBE PAGE widget names don't match ALTER PAGE identifiers #116:

    1. Fixed the TextTemplate path traversal in deriveColumnNameBson to match DESCRIBE's TextTemplate → Template → Items path
    2. Rewrote sanitizeColumnName to exactly match the DESCRIBE side implementation (using strings.Map + strings.TrimFunc and returning empty string for all-underscore results)
  • Test coverage:

    • Added 5 comprehensive regression tests covering attribute binding, caption fallback, all-special-char caption, index fallback, and sanitization trimming
    • Added a bug test MDL script (116-datagrid2-column-name-mismatch.mdl) that demonstrates the fix with a practical example
    • Tests verify the fix works for all column types (attribute-bound, caption-only, and special-character captions)
  • Implementation quality:

    • Changes are minimal and focused - only fixed what was broken
    • Code now exactly matches the DESCRIBE side implementation for consistency
    • Clear comments explain why the intermediate Template document traversal is necessary
    • Proper nil-checks added for edge cases
    • Follows existing code patterns in the file
  • Process adherence:

Recommendation

Approve - This PR correctly fixes the DESCRIBE/ALTER PAGE column name mismatch bug with appropriate tests and minimal, focused changes. The implementation now ensures ALTER PAGE uses the same column name derivation logic as DESCRIBE PAGE, resolving the inconsistency.


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.

DESCRIBE PAGE widget names don't match ALTER PAGE identifiers

2 participants