Skip to content

Commit 456b6df

Browse files
MendixMauclaude
andcommitted
fix(widgets): stop seeding placeholder rows into object lists (closes mendixlabs#1161)
EnsureRequiredObjectLists auto-populated any object list whose nested properties were all "simple" (nothing Attribute/Expression/TextTemplate/ Widgets/DataSource). Studio Pro leaves such a list EMPTY, so the seeded row made the stored instance disagree with the installed .mpk and mxbuild raised CE0463 "the definition of this widget has changed". mxcli check and mx check both reported zero errors on the same model. Measured across the shipped widget templates the heuristic fired on exactly two properties and helped neither: barcodescanner barcodeFormats required, nested {Enumeration} htmlelement events optional, nested {Action,Boolean,Enumeration} barcodeFormats is declared with no `required` attribute at all; the widget XML schema defaults an absent one to true (mpk.go: `Required: p.Required != "false"`), so it arrives marked required and the nested Enumeration does not match the complex-type skip. It seeded one row carrying the enum default AZTEC. Three Barcode Scanners across two pages each raised CE0463; the app would not deploy until Studio Pro's "Update widget" deleted exactly that row. The MCP write path has always had this method as a no-op, so removing the seeding also makes the two engines agree rather than leaving the model dependent on which one authored it. This does NOT touch the sibling fix for mendixlabs#891: filling an *authored* object-list item's required TextTemplate with the widget's shipped translations lives in buildObjectListItemBSON and still applies. An absent `required` attribute in widget XML still means required. Verified on a real app: same MDL script, same model, same mxbuild 11.14.0. before 3x CE0463, BUILD FAILED after 0x CE0463, BUILD SUCCEEDED, no Studio Pro intervention Re-exec is idempotent, and a DataGrid2/Combobox script builds identical error sets before and after. The new test drives Builder.EnsureRequiredObjectLists (the call site used by mdl/backend/mutation.go and mdl/executor/widget_engine.go) and covers both measured properties. It fails against the pre-fix code on both subtests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 643271e commit 456b6df

3 files changed

Lines changed: 208 additions & 92 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1717

1818
### Fixed
1919

20+
- **A Barcode Scanner authored by mxcli failed the build with CE0463** (mendixlabs/mxcli#1161) — `barcodescanner bsCode (datasource: Module.Entity.Code)` was accepted by `mxcli check`, accepted by `mx check`, and then rejected by headless `mxbuild` with `[CE0463] The definition of this widget has changed`, once per instance. The app would not deploy, and the only documented repair was Studio Pro's right-click → "Update widget".
21+
22+
mxcli was seeding one placeholder row into the widget's `barcodeFormats` object list. The trigger is a property the author never mentions: Barcode Scanner 2.5.0 declares `<property key="barcodeFormats" type="object" isList="true">` with **no** `required` attribute, and the widget XML schema defaults an absent `required` to true (`Required: p.Required != "false"`), so the list arrived at the builder marked required. `ensureRequiredObjectLists` then auto-populated it, skipping only lists whose nested properties were Attribute/Expression/TextTemplate/Widgets/DataSource — and `barcodeFormat` is an Enumeration, so nothing skipped it. Studio Pro leaves that list empty; the extra row is the whole difference between a model that deploys and one that does not. Diffed against a Studio-Pro-repaired copy of the same page, the seeded row was the **only** structural delta in the widget's subtree, every scalar property byte-identical.
23+
24+
The seeding is removed rather than narrowed, because measured across the shipped widget templates it reached exactly two properties and helped neither: `barcodescanner barcodeFormats` (above) and `htmlelement events` (optional, nested Action/Boolean/Enumeration), where it wrote a phantom event handler Studio Pro never writes. The MCP write path has always had this method as a no-op, so the two engines now agree instead of the model depending on which one authored it.
25+
26+
This does **not** touch the sibling #891 rule: an object-list item the author DID write still gets its required TextTemplate filled from the widget's shipped translations (`buildObjectListItemBSON`), and an absent `required` in widget XML still means required. Field run (macOS, Mendix 11.14.0, Barcode Scanner 2.5.0): three Barcode Scanner instances across two pages, `mxbuild --target=deploy` at 3 × CE0463 / BUILD FAILED before and 0 × CE0463 / BUILD SUCCEEDED after, from a model authored entirely by mxcli with no Studio Pro intervention.
27+
2028
- **A page's image-collection reference passed `mxcli check --references` and failed the build** (mendixlabs/mxcli#1149) — `staticimage imgAll (Image: 'Atlas_UI_Resources.Atlas_Icons.checkbox_checked')` in a Selection helper's custom state checked clean, exec'd cleanly and then came back as `[error] [CE1613] "The selected image … no longer exists."`, once per state. The report asks for syntax, but the syntax landed with #1057 — describe emits the three `staticimage` lines and re-running the description reports `Unchanged page`, measured on a blank 11.14.0 project. What was missing is that nothing resolved the name #1057 had made writable.
2129

2230
Two holes, and fixing either alone leaves the reported script unchecked. The image reference was collected by **widget type** (`if w.Type == "image"`), so the pluggable widget was resolved and the two widgets #1057 gave the same property — `staticimage`'s `Image` and `dynamicimage`'s `DefaultImage` — were not; it is a table now, so adding a widget that names an image means adding a row. And a page's widgets live in **two** AST fields: `Widgets` is the bare body, while `placeholder <Name> { … }` content is held apart in `Placeholders` (#532). All three page validators walked the first alone, so **every** reference inside a placeholder block — microflow, nanoflow, page, snippet, entity, image — was validated by nothing. Measured, the same button in the two positions: inside `placeholder Main` → `✓ All references valid`; in the bare body → `microflow not found`. That is the shape mxcli's own skills, examples and DESCRIBE output write, so it was the common case rather than an edge one, and it is the third copy of one walk — `validateIconRefs` (#1008) and `forEachWidget` had each grown the placeholder arm separately — so the roots are now collected once.

‎mdl/backend/widgetobj/builder.go‎

Lines changed: 32 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,38 @@ func (ob *Builder) PrimitiveValues() map[string]string {
737737
// Object list defaults
738738
// ---------------------------------------------------------------------------
739739

740-
func (ob *Builder) EnsureRequiredObjectLists() {
741-
ob.object = ensureRequiredObjectLists(ob.object, ob.propertyTypeIDs)
742-
}
740+
// EnsureRequiredObjectLists is intentionally a no-op: mxcli does not seed a
741+
// placeholder row into an object list the author never wrote.
742+
//
743+
// It used to auto-populate any object list whose nested properties were all
744+
// "simple" (nothing Attribute/Expression/TextTemplate/Widgets/DataSource).
745+
// Studio Pro leaves such a list EMPTY, so the seeded row made the stored
746+
// instance disagree with the installed .mpk — CE0463, "the definition of this
747+
// widget has changed".
748+
//
749+
// Measured against the 31 shipped widget templates, the old heuristic fired on
750+
// exactly two properties and helped neither:
751+
//
752+
// barcodescanner barcodeFormats required, nested {Enumeration}
753+
// -> seeded one row carrying the enum default AZTEC; three
754+
// Barcode Scanners on two pages each raised CE0463 and the
755+
// app would not deploy until Studio Pro's "Update widget"
756+
// deleted exactly that row.
757+
// htmlelement events optional, nested {Action,Boolean,Enumeration}
758+
// -> seeded a phantom event handler Studio Pro never writes.
759+
//
760+
// The MCP write path (mdl/backend/mcp.(*mcpWidgetBuilder)) has always had this
761+
// as a no-op, so removing the seeding also makes the two engines agree rather
762+
// than making the model depend on which one authored it.
763+
//
764+
// This is NOT the sibling fix for issue #891. That one fills an *authored*
765+
// object-list item's required TextTemplate with the widget's shipped
766+
// translations, lives in buildObjectListItemBSON, and still applies — an absent
767+
// `required` attribute in widget XML still means required (mpk.go:
768+
// `Required: p.Required != "false"`). Nothing here changes that.
769+
//
770+
// The method is kept so backend.WidgetBuilder keeps its shape.
771+
func (ob *Builder) EnsureRequiredObjectLists() {}
743772

744773
// ---------------------------------------------------------------------------
745774
// Property visibility (#574)
@@ -1410,95 +1439,6 @@ func createDefaultClientTemplateBSON(text string) bson.D {
14101439
// Default object lists
14111440
// ---------------------------------------------------------------------------
14121441

1413-
func ensureRequiredObjectLists(obj bson.D, propertyTypeIDs map[string]pages.PropertyTypeIDEntry) bson.D {
1414-
// Sort keys for deterministic BSON output.
1415-
keys := make([]string, 0, len(propertyTypeIDs))
1416-
for k := range propertyTypeIDs {
1417-
keys = append(keys, k)
1418-
}
1419-
sort.Strings(keys)
1420-
1421-
for _, propKey := range keys {
1422-
entry := propertyTypeIDs[propKey]
1423-
if entry.ObjectTypeID == "" || len(entry.NestedPropertyIDs) == 0 {
1424-
continue
1425-
}
1426-
if !entry.Required {
1427-
hasNestedDS := false
1428-
for _, nested := range entry.NestedPropertyIDs {
1429-
if nested.ValueType == "DataSource" {
1430-
hasNestedDS = true
1431-
break
1432-
}
1433-
}
1434-
if hasNestedDS {
1435-
continue
1436-
}
1437-
}
1438-
// Skip auto-populate when any nested property has a complex ValueType
1439-
// (Attribute / Expression / TextTemplate / Widgets / DataSource).
1440-
// Complex types have no sensible empty default — Studio Pro flags an
1441-
// auto-generated entry with empty Expression/Attribute as CE0463/CE0566.
1442-
// This also avoids over-populating mode-dependent required lists such as
1443-
// Combobox optionsSourceStaticDataSource (only used when source=static).
1444-
hasComplexNested := false
1445-
for _, nested := range entry.NestedPropertyIDs {
1446-
switch nested.ValueType {
1447-
case "Attribute", "Expression", "TextTemplate", "Widgets", "DataSource":
1448-
hasComplexNested = true
1449-
}
1450-
if hasComplexNested {
1451-
break
1452-
}
1453-
}
1454-
if hasComplexNested {
1455-
continue
1456-
}
1457-
obj = updateWidgetPropertyValue(obj, propertyTypeIDs, propKey, func(val bson.D) bson.D {
1458-
for _, elem := range val {
1459-
if elem.Key == "Objects" {
1460-
if arr, ok := elem.Value.(bson.A); ok && len(arr) <= 1 {
1461-
defaultObj := createDefaultWidgetObject(entry.ObjectTypeID, entry.NestedPropertyIDs)
1462-
newArr := bson.A{int32(2), defaultObj}
1463-
result := make(bson.D, 0, len(val))
1464-
for _, e := range val {
1465-
if e.Key == "Objects" {
1466-
result = append(result, bson.E{Key: "Objects", Value: newArr})
1467-
} else {
1468-
result = append(result, e)
1469-
}
1470-
}
1471-
return result
1472-
}
1473-
}
1474-
}
1475-
return val
1476-
})
1477-
}
1478-
return obj
1479-
}
1480-
1481-
func createDefaultWidgetObject(objectTypeID string, nestedProps map[string]pages.PropertyTypeIDEntry) bson.D {
1482-
propsArr := bson.A{int32(2)}
1483-
// Sort keys for deterministic BSON output.
1484-
nestedKeys := make([]string, 0, len(nestedProps))
1485-
for k := range nestedProps {
1486-
nestedKeys = append(nestedKeys, k)
1487-
}
1488-
sort.Strings(nestedKeys)
1489-
for _, k := range nestedKeys {
1490-
entry := nestedProps[k]
1491-
prop := createDefaultWidgetProperty(entry)
1492-
propsArr = append(propsArr, prop)
1493-
}
1494-
return bson.D{
1495-
{Key: "$ID", Value: types.UUIDToBlob(types.GenerateID())},
1496-
{Key: "$Type", Value: "CustomWidgets$WidgetObject"},
1497-
{Key: "TypePointer", Value: types.UUIDToBlob(objectTypeID)},
1498-
{Key: "Properties", Value: propsArr},
1499-
}
1500-
}
1501-
15021442
func createDefaultWidgetProperty(entry pages.PropertyTypeIDEntry) bson.D {
15031443
return bson.D{
15041444
{Key: "$ID", Value: types.UUIDToBlob(types.GenerateID())},
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
// An object list the author never wrote must stay EMPTY.
4+
//
5+
// mxcli used to seed one placeholder row into any object list whose nested
6+
// properties were all "simple" (nothing Attribute/Expression/TextTemplate/
7+
// Widgets/DataSource). Studio Pro leaves such a list empty, so the seeded row
8+
// made the stored instance disagree with the installed .mpk and headless
9+
// mxbuild rejected the page with CE0463 "the definition of this widget has
10+
// changed" — while `mxcli check` and `mx check` both reported zero errors.
11+
//
12+
// Measured against the shipped widget templates, the seeding reached exactly
13+
// two properties and helped neither:
14+
//
15+
// barcodescanner barcodeFormats required, nested {Enumeration}
16+
// htmlelement events optional, nested {Action,Boolean,Enumeration}
17+
//
18+
// Both cases are covered below. This is the inverse of the #891 rule in
19+
// objectlist_required_texttemplate_test.go: an object-list item the author DID
20+
// write still gets its required TextTemplate filled — that path is unchanged.
21+
package widgetobj
22+
23+
import (
24+
"testing"
25+
26+
"github.com/mendixlabs/mxcli/mdl/types"
27+
"github.com/mendixlabs/mxcli/sdk/pages"
28+
"go.mongodb.org/mongo-driver/bson"
29+
)
30+
31+
// emptyObjectListWidget builds a widget object holding one object-list property
32+
// with no rows — the shape a template has before the author writes anything.
33+
func emptyObjectListWidget(entry pages.PropertyTypeIDEntry) bson.D {
34+
return bson.D{
35+
{Key: "$ID", Value: types.UUIDToBlob(types.GenerateID())},
36+
{Key: "$Type", Value: "CustomWidgets$WidgetObject"},
37+
{Key: "TypePointer", Value: types.UUIDToBlob("00000000000000000000000000000000")},
38+
{Key: "Properties", Value: bson.A{
39+
int32(2),
40+
bson.D{
41+
{Key: "$ID", Value: types.UUIDToBlob(types.GenerateID())},
42+
{Key: "$Type", Value: "CustomWidgets$WidgetProperty"},
43+
{Key: "TypePointer", Value: types.UUIDToBlob(entry.PropertyTypeID)},
44+
{Key: "Value", Value: bson.D{
45+
{Key: "$ID", Value: types.UUIDToBlob(types.GenerateID())},
46+
{Key: "$Type", Value: "CustomWidgets$WidgetValue"},
47+
{Key: "Objects", Value: bson.A{int32(2)}},
48+
{Key: "PrimitiveValue", Value: ""},
49+
{Key: "TypePointer", Value: types.UUIDToBlob(entry.ValueTypeID)},
50+
{Key: "Widgets", Value: bson.A{int32(2)}},
51+
}},
52+
},
53+
}},
54+
}
55+
}
56+
57+
// countWidgetObjects reports how many CustomWidgets$WidgetObject nodes sit
58+
// below the root — i.e. how many object-list rows exist.
59+
func countWidgetObjects(v any) int {
60+
n := 0
61+
switch node := v.(type) {
62+
case bson.D:
63+
for _, e := range node {
64+
if e.Key == "$Type" && e.Value == "CustomWidgets$WidgetObject" {
65+
n++
66+
}
67+
}
68+
for _, e := range node {
69+
n += countWidgetObjects(e.Value)
70+
}
71+
case bson.A:
72+
for _, e := range node {
73+
n += countWidgetObjects(e)
74+
}
75+
}
76+
return n
77+
}
78+
79+
// barcodeFormatsEntry mirrors Barcode Scanner 2.5.0's `barcodeFormats`: the XML
80+
// omits `required`, and the schema default for an absent attribute is true
81+
// (mpk.go: `Required: p.Required != "false"`), so it arrives here Required.
82+
func barcodeFormatsEntry() pages.PropertyTypeIDEntry {
83+
return pages.PropertyTypeIDEntry{
84+
PropertyTypeID: "00000000000000000000000000000011",
85+
ValueTypeID: "00000000000000000000000000000012",
86+
ObjectTypeID: "00000000000000000000000000000013",
87+
Required: true,
88+
NestedKeyOrder: []string{"barcodeFormat"},
89+
NestedPropertyIDs: map[string]pages.PropertyTypeIDEntry{
90+
"barcodeFormat": {
91+
PropertyTypeID: "00000000000000000000000000000014",
92+
ValueTypeID: "00000000000000000000000000000015",
93+
ValueType: "Enumeration",
94+
DefaultValue: "AZTEC",
95+
},
96+
},
97+
}
98+
}
99+
100+
// htmlElementEventsEntry mirrors HTML element's `events`: optional, and with no
101+
// nested DataSource it fell past the old not-required guard too.
102+
func htmlElementEventsEntry() pages.PropertyTypeIDEntry {
103+
return pages.PropertyTypeIDEntry{
104+
PropertyTypeID: "00000000000000000000000000000021",
105+
ValueTypeID: "00000000000000000000000000000022",
106+
ObjectTypeID: "00000000000000000000000000000023",
107+
Required: false,
108+
NestedKeyOrder: []string{"eventName", "eventStopPropagation", "eventAction"},
109+
NestedPropertyIDs: map[string]pages.PropertyTypeIDEntry{
110+
"eventName": {
111+
PropertyTypeID: "00000000000000000000000000000024",
112+
ValueTypeID: "00000000000000000000000000000025",
113+
ValueType: "Enumeration",
114+
DefaultValue: "onClick",
115+
},
116+
"eventStopPropagation": {
117+
PropertyTypeID: "00000000000000000000000000000026",
118+
ValueTypeID: "00000000000000000000000000000027",
119+
ValueType: "Boolean",
120+
DefaultValue: "true",
121+
},
122+
"eventAction": {
123+
PropertyTypeID: "00000000000000000000000000000028",
124+
ValueTypeID: "00000000000000000000000000000029",
125+
ValueType: "Action",
126+
},
127+
},
128+
}
129+
}
130+
131+
// Goes through the Builder method the write pipeline actually calls
132+
// (mdl/backend/mutation.go and mdl/executor/widget_engine.go), not a helper, so
133+
// reinstating the seeding fails this test.
134+
func TestEnsureRequiredObjectLists_LeavesUnwrittenListsEmpty(t *testing.T) {
135+
cases := []struct {
136+
name string
137+
propertyKey string
138+
entry pages.PropertyTypeIDEntry
139+
}{
140+
{"barcodescanner barcodeFormats (required, nested Enumeration)", "barcodeFormats", barcodeFormatsEntry()},
141+
{"htmlelement events (optional, nested Action/Boolean/Enumeration)", "events", htmlElementEventsEntry()},
142+
}
143+
144+
for _, tc := range cases {
145+
t.Run(tc.name, func(t *testing.T) {
146+
root := emptyObjectListWidget(tc.entry)
147+
// The root itself is one WidgetObject; any extra is a seeded row.
148+
if before := countWidgetObjects(root); before != 1 {
149+
t.Fatalf("fixture is wrong: expected only the root WidgetObject, got %d", before)
150+
}
151+
152+
ob := New(
153+
"com.example.widget.Test",
154+
bson.D{},
155+
root,
156+
map[string]pages.PropertyTypeIDEntry{tc.propertyKey: tc.entry},
157+
"00000000000000000000000000000013",
158+
nil,
159+
)
160+
ob.EnsureRequiredObjectLists()
161+
162+
if got := countWidgetObjects(ob.object); got != 1 {
163+
t.Errorf("object list %q was auto-populated: %d WidgetObject nodes, want 1 (the root only). "+
164+
"A row Studio Pro does not write is CE0463 at mxbuild time.", tc.propertyKey, got)
165+
}
166+
})
167+
}
168+
}

0 commit comments

Comments
 (0)