Skip to content

Commit 918ac2c

Browse files
committed
fix(widgets): widget sync keeps stored integer widths (#1976)
widgetToMap turned every int32/int64 into float64 and mapToWidgetDoc never turned them back, so a synced widget was written with doubles throughout, including a text box in its slot whose MaxLengthCode -1.0 Mendix reads as unlimited (CE6510). Stored int32/int64 now pass through the map form unchanged; a stored double is tagged so it stays a double; a bare float64 is a number the template pipeline made and is written as int32 (int64 past its range), as create does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011oK82tQYYsMeM1r2ihkNch
1 parent c6b34f8 commit 918ac2c

5 files changed

Lines changed: 249 additions & 6 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"area": "mdl/executor", "date": "2026-11-06", "symptom": "`mxcli widget sync` changing a pluggable widget wrote every int32/int64 in its Type and Object back as a BSON double; a text box in the widget's slot got MaxLengthCode -1.0, which Mendix reads as unlimited (mx check CE6510), and a later 0-change sync did not repair it", "cause": "widgetToMap converted int32/int64 to float64 'so comparisons behave' and mapToWidgetDoc never converted back; TestWidgetRoundTripIsByteStable passed because its fixture stored the array markers as float64, the one width Mendix never uses for them", "file": "mdl/executor/widget_convert.go (widgetToMap, mapToWidgetDoc)", "fix": "Stored int32/int64 pass through the map form unchanged (AugmentTemplate never asserts a number's type); a stored double is tagged storedDouble so it stays a double; a bare float64 is a number the template pipeline made (constructed, or an exemplar cloned through JSON) and is written as int32, int64 past int32's range, as the create path does", "insight": "A byte-stable round-trip test proves nothing about a width its fixture never holds: build fixtures from the widths Studio Pro writes (int32 markers, an int64, a genuine double), and assert per-element BSON types after the operation, not just equality of a value. Settle it with mx check on a copy synced by the old binary (CE6510) against the fixed one (0 errors)", "refs": "ako/mxcli#1976, mendixlabs/mxcli#1748", "test": "mdl/executor/widget_convert_width_test.go; mdl-examples/bug-tests/1976-widget-sync-keeps-integer-widths.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+
- **`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.
1819
- **`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.
1920
- **describe → exec keeps a decision whose true branch is empty** (ako/mxcli#1963, mendixlabs/mxcli#1742) — `describe microflow` folded such a decision into `if not(X) then <false branch> end if;`, and executing that stored `not(X)` with the true and false outcomes swapped: the same behaviour, a different model in Studio Pro. It is now printed as stored, `if X then else <false branch> end if;`, which builds Studio Pro's shape. A script written from the old output still means the same thing; an `alter microflow` target written in the folded `if not(X) then` form no longer resolves, and is refused rather than applied.
2021
- **`marketplace install` installs protected (add-on) modules shipped as `.mxmodule`** — such a package carries its model not as an SQLite `.mpr` but as one BSON document holding the module as a tree, so install failed with `file is not a database`, and `mx module-import` refuses protected modules outright ("Importing protected module is not supported", exit 111). The reference project is now built by splitting that tree into units and writing them with the same raw-unit writer the transplant uses; protection settings travel unchanged. Measured on Menditect's MtaPluginModule 11.5.5 (Marketplace 214717) into an 11.15 MPR v2 app: 32 units, `mx check` 0 errors, module listed as *Protected AddOn*, and the plugin starts and serves its endpoint. The package's declared files (`javasource/`, `javascriptsource/`, …) are written beside the reference project as `mx module-import` would, so `marketplace diff` and `update` do not report every Java or JavaScript action as changed; the units are not converted to the project's Mendix version, so a package saved with a newer Mendix than the project is refused.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
mdl 1;
2+
-- ============================================================================
3+
-- Regression: ako/mxcli#1976 (mendixlabs/mxcli#1748) - widget sync wrote
4+
-- every integer inside a changed widget as a BSON double
5+
-- ============================================================================
6+
--
7+
-- Symptom (before fix):
8+
-- When `mxcli widget sync` changed a pluggable widget, every int32/int64 in
9+
-- its Type and Object came back as a double, including a text box held in
10+
-- the widget's slot. MaxLengthCode -1.0 reads as "unlimited" where -1 means
11+
-- "the attribute's length", so mx check reported
12+
-- CE6510 Maximum length of text box is 'unlimited' but the attribute is
13+
-- limited to 200 characters.
14+
-- A later sync with nothing to change did not repair the unit.
15+
--
16+
-- After fix:
17+
-- Stored integers keep their width through the sync; numbers the sync adds
18+
-- are written as int32, as `create` writes them.
19+
--
20+
-- Usage (needs a stale Fieldset definition to give the sync a change):
21+
-- mxcli exec mdl-examples/bug-tests/1976-widget-sync-keeps-integer-widths.mdl -p app.mpr
22+
-- -- remove <property key="legend"> from Fieldset.xml in widgets/com.mendix.widget.web.Fieldset.mpk
23+
-- mxcli widget sync -p app.mpr --widget com.mendix.widget.web.fieldset.Fieldset
24+
-- mxcli docker check -p app.mpr -- expect 0 errors (CE6510 before the fix)
25+
-- ============================================================================
26+
27+
create module BugTest1976;
28+
create persistent entity BugTest1976.Item ( Name: String(200) );
29+
30+
-- A text box INSIDE a pluggable widget's widgets slot.
31+
create page BugTest1976.PageD ( Title: 'D', Layout: Atlas_Core.PopupLayout, Params: ( $Item: BugTest1976.Item ) ) {
32+
layoutgrid lg { row { column (DesktopWidth: autofill) {
33+
dataview dv (DataSource: $Item) {
34+
fieldset fs {
35+
template slot1 {
36+
textbox tbInner (Label: 'Name', Attribute: Name)
37+
}
38+
}
39+
}
40+
} } }
41+
};

‎mdl/executor/widget_convert.go‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package executor
44

55
import (
6+
"math"
67
"sort"
78
"strings"
89

@@ -59,16 +60,40 @@ func widgetToMap(v any) any {
5960
return bsonutil.BsonBinaryToID(t)
6061
case []byte:
6162
return bsonutil.BsonBinaryToID(bson.Binary{Subtype: 0x00, Data: t})
62-
case int32:
63-
// The template pipeline models Mendix's array markers and small ints as
64-
// float64; keep one numeric representation so comparisons behave.
65-
return float64(t)
66-
case int64:
67-
return float64(t)
63+
case float64:
64+
// A double the unit stores is kept a double on the way back; a bare
65+
// float64 there means a number the template pipeline made (below).
66+
return storedDouble(t)
6867
}
68+
// int32 and int64 pass through at the width the unit stores them: Mendix
69+
// reads the width, so -1.0 as a text box's MaxLengthCode means "unlimited"
70+
// where -1 means "the attribute's length" (CE6510, ako/mxcli#1976).
71+
// AugmentTemplate never asserts a number's type, so it needs no single form.
6972
return v
7073
}
7174

75+
// storedDouble marks a BSON double read from the unit, so mapToWidgetDoc can
76+
// tell it from the float64 numbers AugmentTemplate writes. Those are JSON-shaped
77+
// — the passes construct them as float64, and deepCloneMap round-trips a cloned
78+
// exemplar through JSON — and stand for integers.
79+
type storedDouble float64
80+
81+
// templateNumberToBSON writes a number the template pipeline made the way the
82+
// create path does (widgets.jsonValueToBSONWithMapping): a whole number as
83+
// int32, int64 only when int32 cannot hold it.
84+
func templateNumberToBSON(f float64) any {
85+
if f != math.Trunc(f) || math.IsInf(f, 0) {
86+
return f
87+
}
88+
if f >= math.MinInt32 && f <= math.MaxInt32 {
89+
return int32(f)
90+
}
91+
if f >= math.MinInt64 && f < math.MaxInt64 {
92+
return int64(f)
93+
}
94+
return f
95+
}
96+
7297
// mapToWidgetDoc converts back, restoring binary IDs and alphabetical key order.
7398
func mapToWidgetDoc(v any) any {
7499
switch t := v.(type) {
@@ -89,6 +114,10 @@ func mapToWidgetDoc(v any) any {
89114
out[i] = mapToWidgetDoc(item)
90115
}
91116
return out
117+
case storedDouble:
118+
return float64(t)
119+
case float64:
120+
return templateNumberToBSON(t)
92121
}
93122
return v
94123
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package executor
4+
5+
import (
6+
"bytes"
7+
"testing"
8+
9+
"go.mongodb.org/mongo-driver/v2/bson"
10+
11+
"github.com/mendixlabs/mxcli/modelsdk/widgets/mpk"
12+
)
13+
14+
func widthTestID(b byte) bson.Binary {
15+
return bson.Binary{Subtype: 0x00, Data: bytes.Repeat([]byte{b}, 16)}
16+
}
17+
18+
// slotWidget is a pluggable widget shaped like a Fieldset holding a text box in
19+
// its `content` slot, with a second property `legend` that the definition below
20+
// no longer declares, so a sync removes it. Integers are stored the way
21+
// Studio Pro and `exec` store them: int32 markers and fields, one int64.
22+
func fieldsetWithSlotTextBox() bson.D {
23+
textBox := bson.D{
24+
{Key: "$ID", Value: widthTestID(0x20)},
25+
{Key: "$Type", Value: "Forms$TextBox"},
26+
{Key: "DecimalPrecision", Value: int64(2)},
27+
{Key: "MaxLengthCode", Value: int32(-1)},
28+
{Key: "Name", Value: "tbInner"},
29+
{Key: "TabIndex", Value: int32(0)},
30+
{Key: "Weight", Value: float64(0.5)},
31+
}
32+
prop := func(id, typeID byte, value bson.D) bson.D {
33+
return bson.D{
34+
{Key: "$ID", Value: widthTestID(id)},
35+
{Key: "$Type", Value: "CustomWidgets$WidgetProperty"},
36+
{Key: "TypePointer", Value: widthTestID(typeID)},
37+
{Key: "Value", Value: value},
38+
}
39+
}
40+
propType := func(id byte, key, typ string) bson.D {
41+
return bson.D{
42+
{Key: "$ID", Value: widthTestID(id)},
43+
{Key: "$Type", Value: "CustomWidgets$WidgetPropertyType"},
44+
{Key: "Caption", Value: key},
45+
{Key: "Category", Value: "General"},
46+
{Key: "Description", Value: ""},
47+
{Key: "IsDefault", Value: false},
48+
{Key: "PropertyKey", Value: key},
49+
{Key: "ValueType", Value: bson.D{
50+
{Key: "$ID", Value: widthTestID(id + 1)},
51+
{Key: "$Type", Value: "CustomWidgets$WidgetValueType"},
52+
{Key: "EnumerationValues", Value: bson.A{int32(2)}},
53+
{Key: "Translations", Value: bson.A{int32(2)}},
54+
{Key: "Type", Value: typ},
55+
}},
56+
}
57+
}
58+
return bson.D{
59+
{Key: "$ID", Value: widthTestID(0x01)},
60+
{Key: "$Type", Value: "CustomWidgets$CustomWidget"},
61+
{Key: "Name", Value: "fs"},
62+
{Key: "Object", Value: bson.D{
63+
{Key: "$ID", Value: widthTestID(0x02)},
64+
{Key: "$Type", Value: "CustomWidgets$WidgetObject"},
65+
{Key: "Properties", Value: bson.A{
66+
int32(2),
67+
prop(0x03, 0x10, bson.D{
68+
{Key: "$ID", Value: widthTestID(0x04)},
69+
{Key: "$Type", Value: "CustomWidgets$WidgetValue"},
70+
{Key: "PrimitiveValue", Value: "Legend"},
71+
{Key: "Widgets", Value: bson.A{int32(2)}},
72+
}),
73+
prop(0x05, 0x12, bson.D{
74+
{Key: "$ID", Value: widthTestID(0x06)},
75+
{Key: "$Type", Value: "CustomWidgets$WidgetValue"},
76+
{Key: "PrimitiveValue", Value: ""},
77+
{Key: "Widgets", Value: bson.A{int32(2), textBox}},
78+
}),
79+
}},
80+
}},
81+
{Key: "Type", Value: bson.D{
82+
{Key: "$ID", Value: widthTestID(0x07)},
83+
{Key: "$Type", Value: "CustomWidgets$CustomWidgetType"},
84+
{Key: "ObjectType", Value: bson.D{
85+
{Key: "$ID", Value: widthTestID(0x08)},
86+
{Key: "$Type", Value: "CustomWidgets$WidgetObjectType"},
87+
{Key: "PropertyTypes", Value: bson.A{
88+
int32(2),
89+
propType(0x10, "legend", "String"),
90+
propType(0x12, "content", "Widgets"),
91+
}},
92+
}},
93+
{Key: "WidgetId", Value: "com.mendix.widget.web.fieldset.Fieldset"},
94+
}},
95+
}
96+
}
97+
98+
// ako/mxcli#1976 (mendixlabs/mxcli#1748): the map form turned every int32 and
99+
// int64 into float64 and nothing turned them back, so a synced widget was
100+
// written with doubles throughout, and a text box in its slot read
101+
// MaxLengthCode -1.0 as "unlimited" (CE6510). The round trip with no
102+
// reconciliation must be byte-identical for every numeric width Mendix stores,
103+
// a genuine double included.
104+
func TestWidgetRoundTripKeepsNumericWidths(t *testing.T) {
105+
widget := fieldsetWithSlotTextBox()
106+
original, err := bson.Marshal(widget)
107+
if err != nil {
108+
t.Fatal(err)
109+
}
110+
back, ok := mapToWidgetDoc(widgetToMap(widget)).(bson.D)
111+
if !ok {
112+
t.Fatal("mapToWidgetDoc did not return a bson.D")
113+
}
114+
encoded, err := bson.Marshal(back)
115+
if err != nil {
116+
t.Fatal(err)
117+
}
118+
if !bytes.Equal(original, encoded) {
119+
t.Errorf("round trip changed the document:\n got %v", back)
120+
}
121+
}
122+
123+
// The same, through the sync itself: dropping the stale `legend` property must
124+
// leave the text box in the slot, and every marker, at its stored width.
125+
func TestWidgetSyncKeepsNumericWidthsInSlot(t *testing.T) {
126+
def := &mpk.WidgetDefinition{
127+
ID: "com.mendix.widget.web.fieldset.Fieldset",
128+
IsPluggable: true,
129+
Properties: []mpk.PropertyDef{{Key: "content", Type: "widgets", Caption: "content", Category: "General"}},
130+
}
131+
got, ok := applyToWidget(fieldsetWithSlotTextBox(), def)
132+
if !ok {
133+
t.Fatal("applyToWidget reported no change")
134+
}
135+
raw, err := bson.Marshal(got)
136+
if err != nil {
137+
t.Fatal(err)
138+
}
139+
var doubles []string
140+
walkRaw(bson.Raw(raw), "", func(path string, v bson.RawValue) {
141+
if v.Type == bson.TypeDouble && path != "Object.Properties.1.Value.Widgets.1.Weight" {
142+
doubles = append(doubles, path)
143+
}
144+
})
145+
if len(doubles) > 0 {
146+
t.Errorf("sync wrote integers as doubles at: %v", doubles)
147+
}
148+
if bytes.Contains(raw, []byte("legend")) {
149+
t.Error("the stale property was not removed; the test does not exercise a change")
150+
}
151+
}
152+
153+
// walkRaw visits every leaf of a raw document with its dotted path.
154+
func walkRaw(doc bson.Raw, prefix string, visit func(string, bson.RawValue)) {
155+
elems, _ := doc.Elements()
156+
for _, e := range elems {
157+
path := e.Key()
158+
if prefix != "" {
159+
path = prefix + "." + path
160+
}
161+
v := e.Value()
162+
switch v.Type {
163+
case bson.TypeEmbeddedDocument:
164+
walkRaw(v.Document(), path, visit)
165+
case bson.TypeArray:
166+
walkRaw(bson.Raw(v.Array()), path, visit)
167+
default:
168+
visit(path, v)
169+
}
170+
}
171+
}

0 commit comments

Comments
 (0)