Skip to content

Commit 819a29a

Browse files
authored
Merge pull request #1994 from ako/claude/wonderful-hypatia-x7mmyq
fix(constants): write ExportLevel Hidden, keep the stored level on rewrite (#1980)
2 parents e21b56d + e7c9ddc commit 819a29a

5 files changed

Lines changed: 98 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"area": "mdl/backend", "date": "2026-11-06", "symptom": "`create constant` stored ExportLevel \"\" where Studio Pro writes \"Hidden\"; mx check accepted it, but mx diff of that unit against a \"Hidden\" copy on another branch crashed (exit 129, Value cannot be null. (Parameter 'element')) and git merge lost its property report; `create or modify constant` also turned a stored API/Hidden into \"\"", "cause": "constToGen wrote c.ExportLevel verbatim, and constants have no MDL spelling for it, so the executor's model always carried \"\"; UpdateConstant was the one rewrite path not routed through keepStoredExportLevel, and so missing from TestUpdatePaths_KeepStoredExportLevel's enumeration", "file": "mdl/backend/modelsdk/constant_write.go (constToGen, UpdateConstant)", "fix": "constToGen defaults to \"Hidden\" (orDefault, as every other writer); UpdateConstant keeps the stored level via keepStoredExportLevel, which ignores a stored \"\" and so also repairs units an earlier version wrote", "insight": "An enum value mx check accepts can still break Mendix's own tooling: measure the consumer that fails (mx diff of a \"\" copy against a \"Hidden\" copy: 129; two \"Hidden\" copies: 0), not just the build. When a carry helper is enumerated by a table test, a writer missing from the table is the bug — grep the writers for SetExportLevel without orDefault", "refs": "ako/mxcli#1980, mendixlabs/mxcli#1749", "test": "mdl/backend/modelsdk/issue816_export_level_test.go (Constant case, TestConstant_ExportLevelDefaultsToHidden); mdl-examples/bug-tests/1980-constant-export-level-hidden.mdl"}

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1515

1616
### Fixed
1717

18+
- **`create constant` writes `ExportLevel: Hidden`, as Studio Pro does** (ako/mxcli#1980, mendixlabs/mxcli#1749) — it wrote `""`, which `mx check` accepts but `mx diff` crashes on against a `Hidden` copy (exit 129), taking `git merge`'s report with it. `create or modify constant` now keeps a stored level instead of clearing it, and repairs a stored `""`.
1819
- **`widget sync` keeps the integers it does not change as integers** (ako/mxcli#1976, mendixlabs/mxcli#1748) — syncing a widget wrote every int32 and int64 in it back as a double, a text box in the widget's slot included, whose `MaxLengthCode -1.0` Mendix reads as unlimited (CE6510). A unit already synced by an earlier version keeps its doubles; re-create the page to repair it.
1920
- **A Marketplace Calendar written by mxcli passes a plain `mx check`** (mendixlabs/mxcli#1632) — every Calendar failed with CE0463 "The definition of this widget has changed" until `mxcli fix widgets` or Studio Pro's "Update all widgets"; `mxcli docker check` hid it, since it runs that update on a temporary copy first. The Calendar's `toolbarItems` object list declares its sub-properties directly under `<properties>`, not inside a `<propertyGroup>`, and the `.mpk` parser behind generated widget templates read only the grouped shape, so the list was stored with no definition of its items. Both shapes are now read, a direct sub-property takes its category from its own `<category>` element, and the stored Calendar equals what `mx update-widgets` writes. The other object-list widgets in `doctype-tests/32-pluggable-widget-object-lists-v010.mdl` (Accordion, PopupMenu, Maps, area and line chart, heat map) are stored unchanged.
2021
- **`alter workflow` no longer guesses which outcome to drop** (ako/mxcli#808) — `drop X outcome 'V'` with two outcomes of value `V` dropped the first; it is refused as ambiguous now. `check --references` also resolves an activity reference by name before caption, as `exec` does, so its guards no longer go silent on a target captioned like another activity's name.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
mdl 1;
2+
-- ============================================================================
3+
-- Regression: ako/mxcli#1980 (mendixlabs/mxcli#1749) - create constant wrote
4+
-- ExportLevel "" where Studio Pro writes "Hidden"
5+
-- ============================================================================
6+
--
7+
-- Symptom (before fix):
8+
-- `create constant` stored "ExportLevel": "". mx check accepts it, but once
9+
-- another branch holds the same constant with "Hidden", mx diff crashes on
10+
-- the pair (exit 129, "Value cannot be null. (Parameter 'element')") and
11+
-- `mxcli git merge` loses its property-level report. `create or modify
12+
-- constant` also turned a stored "API" or "Hidden" into "".
13+
--
14+
-- After fix:
15+
-- A new constant is written with "Hidden"; a rewrite keeps the stored level,
16+
-- and repairs a stored "" to "Hidden". Measured on 11.14.0: mx diff of a ""
17+
-- copy against a "Hidden" copy exits 129; of two "Hidden" copies, 0.
18+
--
19+
-- Usage:
20+
-- mxcli exec mdl-examples/bug-tests/1980-constant-export-level-hidden.mdl -p app.mpr
21+
-- mxcli bson dump -p app.mpr -t constant -o BugTest1980.Enabled -- "ExportLevel": "Hidden"
22+
-- mxcli docker check -p app.mpr -- expect 0 errors
23+
-- ============================================================================
24+
25+
create module BugTest1980;
26+
create constant BugTest1980.Enabled ( Type: boolean, DefaultValue: true );
27+
create or modify constant BugTest1980.Enabled ( Type: boolean, DefaultValue: false );

‎mdl/backend/modelsdk/constant_write.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func (b *Backend) UpdateConstant(c *model.Constant) error {
5151
if err != nil {
5252
return fmt.Errorf("UpdateConstant: encode: %w", err)
5353
}
54+
// A constant has no MDL spelling for its export level, so the rewrite keeps
55+
// the stored one: the executor's model carries none, and constToGen's
56+
// "Hidden" would otherwise turn an API constant Hidden (ako/mxcli#1980).
57+
contents, err = b.keepStoredExportLevel(string(c.ID), contents)
58+
if err != nil {
59+
return fmt.Errorf("UpdateConstant: %w", err)
60+
}
5461
return b.writer.UpdateRawUnit(string(c.ID), contents)
5562
}
5663

@@ -72,7 +79,10 @@ func constToGen(c *model.Constant) *genConst.Constant {
7279
out.SetName(c.Name)
7380
out.SetDocumentation(c.Documentation)
7481
out.SetExcluded(c.Excluded)
75-
out.SetExportLevel(c.ExportLevel)
82+
// Studio Pro writes "Hidden". An empty value passes mx check, but mx diff
83+
// crashes comparing it with "Hidden" on another branch, which takes git
84+
// merge's property report with it (ako/mxcli#1980).
85+
out.SetExportLevel(orDefault(c.ExportLevel, "Hidden"))
7686
out.SetType(constantDataTypeToGen(c.Type))
7787
out.SetDefaultValue(c.DefaultValue)
7888
out.SetExposedToClient(c.ExposedToClient)

‎mdl/backend/modelsdk/issue816_export_level_test.go‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,22 @@ var exportLevelCases = []exportLevelCase{
402402
return b.UpdateDataTransformer(&model.DataTransformer{BaseElement: model.BaseElement{ID: id}, ContainerID: firstModuleID(t, b), Name: "Issue816Transformer", SourceType: "JSON", SourceJSON: "{}"})
403403
},
404404
},
405+
{
406+
// Constants have no MDL spelling for their export level, and the
407+
// executor builds the model without one (ako/mxcli#1980).
408+
name: "Constant",
409+
subject: func(t *testing.T, b *Backend) model.ID {
410+
c := issue1980Constant(firstModuleID(t, b), "")
411+
if err := b.CreateConstant(c); err != nil {
412+
t.Fatalf("create constant: %v", err)
413+
}
414+
return c.ID
415+
},
416+
rewrite: func(t *testing.T, b *Backend, id model.ID, _ string) error {
417+
c := issue1980Constant(firstModuleID(t, b), id)
418+
return b.UpdateConstant(c)
419+
},
420+
},
405421
{
406422
name: "AgentEditorModel",
407423
subject: func(t *testing.T, b *Backend) model.ID {
@@ -524,3 +540,45 @@ func TestWithExportLevel_ReplacesOnlyTheValue(t *testing.T) {
524540
t.Errorf("no ExportLevel key: want the input unchanged (no key added), err=%v", err)
525541
}
526542
}
543+
544+
func issue1980Constant(container, id model.ID) *model.Constant {
545+
return &model.Constant{
546+
BaseElement: model.BaseElement{ID: id},
547+
ContainerID: container,
548+
Name: "Issue1980Constant",
549+
Type: model.ConstantDataType{Kind: "Boolean"},
550+
DefaultValue: "true",
551+
}
552+
}
553+
554+
// ako/mxcli#1980 (mendixlabs/mxcli#1749): `create constant` wrote ExportLevel ""
555+
// where Studio Pro writes "Hidden". mx check accepts it, but mx diff crashes on
556+
// a pair of units holding "" and "Hidden", and git merge's report goes with it.
557+
// A rewrite also repairs a unit an earlier version left at "".
558+
func TestConstant_ExportLevelDefaultsToHidden(t *testing.T) {
559+
src := filepath.Join("..", "..", "..", "testdata", "testapp", "TestApp")
560+
if _, err := os.Stat(filepath.Join(src, "TestApp.mpr")); err != nil {
561+
t.Skipf("TestApp submodule not initialised: %v", err)
562+
}
563+
proj := copyTestAppFixture(t, src)
564+
b := New()
565+
if err := b.Connect(proj); err != nil {
566+
t.Fatalf("connect: %v", err)
567+
}
568+
defer b.Disconnect()
569+
570+
c := issue1980Constant(firstModuleID(t, b), "")
571+
if err := b.CreateConstant(c); err != nil {
572+
t.Fatal(err)
573+
}
574+
if got := storedExportLevel(t, b, c.ID); got != "Hidden" {
575+
t.Fatalf("create constant wrote ExportLevel %q, want Hidden", got)
576+
}
577+
setStoredExportLevel(t, b, c.ID, "")
578+
if err := b.UpdateConstant(issue1980Constant(firstModuleID(t, b), c.ID)); err != nil {
579+
t.Fatal(err)
580+
}
581+
if got := storedExportLevel(t, b, c.ID); got != "Hidden" {
582+
t.Errorf("rewriting a constant stored with ExportLevel \"\" wrote %q, want Hidden", got)
583+
}
584+
}

0 commit comments

Comments
 (0)