Skip to content

Commit 24c44ef

Browse files
committed
fix(widgets): expression props from the installed .mpk are persisted, and described
MDL-WIDGET06 told authors File Uploader's maxFilesPerUpload 'will be dropped' although the explicit pass writes it: its type was looked up in the embedded template only. Fall back to the project's installed package. Describe also never read expression-typed pluggable properties back; emit the ones that differ from the package default. Field run: ProcureFlow (Mendix 11.14.0) scratch copy — fileuploader with maxFilesPerUpload: '1': no warning, stored Expression 1, describe prints it, untouched Invoice_Upload (default 10) describes as before, mx check 0 errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D5dJ4raEjbm8bFiKeYtchS
1 parent 9509176 commit 24c44ef

6 files changed

Lines changed: 204 additions & 3 deletions

File tree

‎.claude/skills/fix-issue/findings/mdl-executor.jsonl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,4 @@
713713
{"area": "mdl/executor", "date": "2026-09-25", "symptom": "`textbox t (Attribute: FullName)` at the top of a page (CREATE PAGE/SNIPPET, a plain container, or ALTER PAGE … INSERT at page level) passed plain `mxcli check`, `exec --no-check`/ALTER reported success, and `bson dump` showed `AttributeRef: null` — mxbuild 11.13.0: CE0544 \"This widget can only function inside a data context\" + CE7005 (textbox/textarea/datepicker/checkbox/radiobuttons/dropdown), CE0402 (dynamictext Attribute:), CE0642 (combobox). Qualified `Mod.Ent.Attr` there is stored and fails CE0544/CE2421/CE1365/CE7247 \"Move this widget into a data container\" + CE7006. `Attribute: $P/Attr` / `$currentObject/Attr` dropped even INSIDE a data view.", "cause": "resolveAttributePath returns the bare name when entityContext is \"\", and attributeRefToGen (and widgetobj setAttributeRefField) write nil for any path with < 2 dots, so the binding vanished between builder and writer; refuseBareAttributeRefs never sees it because no Attribute string is emitted. The only refusal (validatePageContextTree) runs in the --references phase for CREATE PAGE/SNIPPET, so plain check, --no-check and ALTER were unguarded. `$x/Attr` parses via the generic property rule as an *ast.DataSourceV3, so GetAttribute() returns \"\" and every builder skipped it.", "file": "mdl/executor/cmd_pages_input_binding_context.go (inputBindingProblem, checkInputBinding, validateInputBindingContext = MDL-WIDGET34), wired in cmd_pages_builder_v3_widgets.go (6 input builders + buildDynamicTextV3), widget_engine.go (primary Attribute mapping), validate_widgets.go (validateWidgetTreeIn); tests cmd_pages_input_binding_context_test.go; bug-tests input-binding-without-context{,.fail}.mdl", "insight": "Reuse the MDL-PAGEARG01 three-state context (pageArgContext known/present) rather than entityContext==\"\" as the 'outside a data container' signal: entityContext is also empty INSIDE a container whose flow cannot be resolved (excluded ShareFeedback_Logo), where DESCRIBE writes qualified names that must keep building — refusing qualified-on-empty-entity would have broken that round trip. So known-absent context refuses bare AND qualified; unknown context (ALTER) refuses only the bare name the writer provably nulls. Two existing unit tests (OnChangeSurvivesBuilder, DynamicTextV3_AttributeBinds) built inputs with NO entity and passed — the second asserted a bare `Title` AttributeRef counted as 'bound', i.e. it pinned the bug: when a fixture has no entity context, ask what the writer does with its output. The `$P/Attr` drop was found only by dumping the control page, not from the report — print the AST value type with a probe test before assuming a spelling reaches the builder. Evidence: 22 mxbuild errors before on the probe matrix; after, every case refused with nothing written, controls (dataview/listview/gallery/datagrid/snippet dataview/ALTER into dataview) 0 errors, 17/17 stock pages + 4/4 snippets describe→exec round trip.", "refs": ["MDL-WIDGET34"], "ce": ["CE0544", "CE7005", "CE0402", "CE0642", "CE2421", "CE1365", "CE7247", "CE7006"]}
714714
{"area":"mdl/executor","date":"2026-09-25","symptom":"`alter page FeedbackModule.ShareFeedback_Logo { insert after textBox1 { image zzImg (ImageType: imageUrl, ImageUrl: '{1}', ImageUrlParams: [{1} = ImageB64]) } }` passed `check --references`; exec wrote a bare AttributeRef and `mx check` could not LOAD the project (ArgumentNullException setting 'Attribute'). Same at page top level outside any data container; a text box's `Attribute:` there is silently dropped (CE7005).","cause":"ALTER's entity context comes from the STORED document (nearest enclosing data source, or a flow source's return type via resolveDataSourceFlowEntity). With the flow missing (Feedback v4.0.2 ships no DS_FeedbackForm) or no container at all, entityContext is \"\" and resolveAttributePath returns the bare name. CREATE PAGE refused this at check time (relaxExcludedWidgetRefs/unscopedBindings, #678); ALTER's check never opened the document, so nothing could know the scope.","file":"mdl/executor/validate_alter_unscoped.go, mdl/executor/cmd_alter_page.go (alterEntityContext), mdl/executor/validate.go (bindingsWithoutScope)","insight":"For ALTER, scope is a property of the stored document, not the statement: a check-time question about it must open the document (OpenPageForMutation, never Save; validate_alter_set.go already does this) and ask through the SAME function exec uses, so the INSERT/REPLACE entity resolution was lifted into alterEntityContext rather than restated, and the binding walk lifted out of unscopedBindings (bindingsWithoutScope) rather than copied. Controls that keep it from blocking working scripts: skip a target the stored doc lacks (added earlier in the script), a flow the script declares with an entity return (sc.flowParams), DataGrid2 column and list-view-template paths, and documents the script creates. Reproduce with a Studio Pro-authored page whose flow is genuinely absent.","refs":["#678","#685"]}
715715
{"area": "mdl/executor", "date": "2026-09-25", "symptom": "`describe page` on a File Uploader (files mode) emits `DataSource: association …`, and exec of that output fails: \"widget `upFiles` (fileuploader) exposes 2 datasources, so a generic `datasource:` clause is ambiguous — name the one you mean: associatedFiles, associatedImages\"", "cause": "DESCRIBE chose generic vs named by counting CONFIGURED datasources (namedCustomWidgetDataSources drops unset ones, so files mode = 1), while the builder's refuseAmbiguousGenericDataSource counts DECLARED datasource mappings (a generated def maps every top-level datasource = 2). Two sides of one round trip deciding the same question from different evidence.", "file": "mdl/executor/cmd_pages_describe_parse.go", "insight": "When describe and build each decide 'is this ambiguous?', they must count the same set. Fix read the DECLARED count from the stored schema (PropertyTypes with ValueType.Type=DataSource, excluding IsLinked) and excluded widgets with an embedded .def.json — those are hand-written and pick one datasource mapping per mode, so a database-mode ComboBox (two declared) must keep the generic clause. The #956 bug-test script itself authored the refused generic clause on a File Uploader: a bug-test that only runs `mxcli check` without a project can't see an exec-time refusal, so grep bug-tests for the old spelling whenever a builder starts refusing one.", "refs": ["mendixlabs/mxcli#1199", "mendixlabs/mxcli#956", "mendixlabs/mxcli#1109"], "rules": []}
716+
{"area": "mdl/executor", "date": "2026-09-26", "symptom": "`fileuploader u (…, maxFilesPerUpload: '1')` warns MDL-WIDGET06 'recognized but not yet persisted — a non-default value will be dropped', yet the stored widget carries Expression \"1\"; describe does not print maxFilesPerUpload, so replaying describe output resets it to 10", "cause": "persistedByExplicitPass looked the property type up in the embedded template only (mwidgets.GetTemplate), which predates File Uploader 2.5.0's maxFilesPerUpload, so the type was unknown and the warning kept; extractExplicitProperties read AttributeRef, TextTemplate and PrimitiveValue but never WidgetValue.Expression.", "file": "mdl/executor/validate_widget_explicit_writable.go", "insight": "The writer builds from the project's INSTALLED .mpk; any checker question about what the writer does must consult the same source, not the embedded template. A false 'will be dropped' is a silent drop of the author's intent: a real project left the setting for Studio Pro on the strength of it. Settled by reading back WidgetValue.Expression of the stored property.", "rules": ["MDL-WIDGET06"]}

‎CHANGELOG.md‎

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

1515
### Fixed
1616

17+
- **An expression property newer than mxcli's embedded widget template was reported as dropped, and `describe` lost it** — File Uploader 2.5.0's `maxFilesPerUpload` ("Maximum number of files") is written by `fileuploader u (…, maxFilesPerUpload: '1')`, yet MDL-WIDGET06 said it "will be dropped": the type was looked up in the embedded template only. It is now read from the project's installed package as well. `describe` never read expression-typed pluggable properties back, so replaying its output reset them to the default; it now emits the ones that differ from the package's declared default.
1718
- **Keyword operators were fused in some stored expressions** — a page action's microflow argument `Flag: $a and $b` was stored as `$aand$b`, `if $x then 'a' else 'b'` as `if$xthen'a'else'b'`; the same in `contentparams` values, `send rest request … with (…)` parameters and a dynamic `execute database query`. Those four places took the expression's text without its whitespace; literals, `+` and `$currentObject` were unaffected, which is why it went unnoticed, and `check --references` passed. Measured by decoding the stored units on a Mendix 11.14.0 project. The expression is now stored as written, with MDL comments removed, as the microflow expression sites already did.
1819
- **An input bound to an attribute outside any data container was written with no binding** — `textbox t (Attribute: FullName)` at the top of a page (or of a snippet, or inside a plain container) has no entity to qualify the name with, and the writer stored it as `AttributeRef: null`. Plain `check` passed, `exec --no-check` and `alter page … insert` at page level said success, and mxbuild 11.13.0 failed the page with CE0544 "This widget can only function inside a data context" + CE7005 (text box, text area, date picker, check box, radio buttons, drop-down), CE0402 (dynamic text `Attribute:`) or CE0642 (combo box). A qualified attribute there is stored and fails the same way (CE0544 / CE2421 / CE1365 / CE7247 "Move this widget into a data container"). `Attribute: $P/Name` and `Attribute: $currentObject/Name` never parsed as an attribute path and were dropped even inside a data view. `check` now reports all three as **MDL-WIDGET34** (no project needed), and the page builder refuses them with the widget named, so nothing is written; `alter page` refuses a bare name it has no entity for. Place the widget in a data view, list view, gallery or data grid and bind the attribute by name.
1920
- **An expression property written in brackets was silently dropped** (mendixlabs/mxcli#750) — `dynamicclasses: [ if $currentObject/Featured then 'a' else 'b' ]`, the spelling #750 proposes, parsed as a list that no writer reads: `check` was clean, `exec` said `Created page`, and the widget was stored with no dynamic class. `alter page … set DynamicClasses = [ … ]` said `Altered page` and changed nothing, and a column's `DynamicCellClass` stored the list's text — tokens fused, `[if$x/Ythen'a'else'b']` — as its expression. Measured on a copy of a Mendix 11.14.0 project with the pre-fix binary. `mxcli check` now reports **MDL-WIDGET32** for `DynamicClasses` and `DynamicCellClass` written as a list (no project needed), and ALTER refuses it, so `check -p` reports that too. Write the expression quoted.

‎mdl/executor/cmd_pages_describe_pluggable.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,22 @@ func extractExplicitProperties(ctx *ExecContext, w map[string]any) []rawExplicit
12091209
continue
12101210
}
12111211

1212+
// An expression-typed property (File Uploader `maxFilesPerUpload`, …).
1213+
// The explicit pass writes it from `key: 'expr'`, but describe never
1214+
// read it back, so replaying describe output reset it to the default.
1215+
// A value equal to the package's declared default is left out, so an
1216+
// untouched widget describes as before.
1217+
if valueTypes[typePointerID] == "Expression" {
1218+
if expr := extractString(value["Expression"]); expr != "" && expr != expressionDefault(ctx, w, propKey) {
1219+
result = append(result, rawExplicitProp{
1220+
Key: propKey,
1221+
Value: expr,
1222+
ValueType: "Expression",
1223+
})
1224+
}
1225+
continue
1226+
}
1227+
12121228
// Check for a PrimitiveValue.
12131229
//
12141230
// Booleans used to be dropped here as "common defaults". They are not:
@@ -1535,3 +1551,14 @@ var embeddedDefinitionWidgetIDs = sync.OnceValue(func() map[string]bool {
15351551
}
15361552
return ids
15371553
})
1554+
1555+
// expressionDefault returns the installed package's declared default for a
1556+
// widget's top-level property, or "" when there is no project or package.
1557+
func expressionDefault(ctx *ExecContext, w map[string]any, propKey string) string {
1558+
if ctx == nil || ctx.MprPath == "" {
1559+
return ""
1560+
}
1561+
wt, _ := w["Type"].(map[string]any)
1562+
widgetID := extractString(wt["WidgetId"])
1563+
return widgetPropertyDefaults(ctx.MprPath, widgetID)[defaultsKey("", propKey)]
1564+
}

‎mdl/executor/validate_widget_explicit_writable.go‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
package executor
44

55
import (
6+
"path/filepath"
67
"strings"
78
"sync"
89

910
mwidgets "github.com/mendixlabs/mxcli/modelsdk/widgets"
11+
"github.com/mendixlabs/mxcli/modelsdk/widgets/mpk"
1012
)
1113

1214
// explicitPassWritableTypes are the property value types the widget engine's
@@ -52,6 +54,47 @@ func widgetPropertyTypes(widgetID string) map[string]string {
5254
//
5355
// An unknown type keeps the warning: saying "not persisted" for something that
5456
// is, is the lesser error than the reverse.
55-
func persistedByExplicitPass(widgetID, lowerKey string) bool {
56-
return explicitPassWritableTypes[widgetPropertyTypes(widgetID)[lowerKey]]
57+
//
58+
// The type comes from the embedded template first and, failing that, from the
59+
// project's INSTALLED package — the one the writer builds from. A property newer
60+
// than the embedded template (File Uploader 2.5.0's `maxFilesPerUpload`, an
61+
// expression) is written by the explicit pass, and was still warned "will be
62+
// dropped" because only the embedded template was consulted.
63+
func persistedByExplicitPass(widgetID, lowerKey, projectPath string) bool {
64+
t := widgetPropertyTypes(widgetID)[lowerKey]
65+
if t == "" {
66+
t = installedWidgetPropertyTypes(projectPath, widgetID)[lowerKey]
67+
}
68+
return explicitPassWritableTypes[t]
69+
}
70+
71+
var installedPropertyTypesCache sync.Map // projectPath\x00widgetID → map[lowercased key]lowercased type
72+
73+
// installedWidgetPropertyTypes returns each top-level property's declared type
74+
// from the widget's .mpk in the project's widgets/ folder. Empty without a
75+
// project or a package.
76+
func installedWidgetPropertyTypes(projectPath, widgetID string) map[string]string {
77+
if projectPath == "" || widgetID == "" {
78+
return nil
79+
}
80+
cacheKey := projectPath + "\x00" + widgetID
81+
if v, ok := installedPropertyTypesCache.Load(cacheKey); ok {
82+
return v.(map[string]string)
83+
}
84+
out := map[string]string{}
85+
projectDir := projectPath
86+
if strings.EqualFold(filepath.Ext(projectDir), ".mpr") {
87+
projectDir = filepath.Dir(projectDir)
88+
}
89+
if mpkPath, err := mpk.FindMPK(projectDir, widgetID); err == nil && mpkPath != "" {
90+
if wd, err := mpk.ParseMPKForWidget(mpkPath, widgetID); err == nil && wd != nil {
91+
for _, p := range wd.Properties {
92+
if p.Key != "" && p.Type != "" {
93+
out[strings.ToLower(p.Key)] = strings.ToLower(p.Type)
94+
}
95+
}
96+
}
97+
}
98+
installedPropertyTypesCache.Store(cacheKey, out)
99+
return out
57100
}

‎mdl/executor/validate_widgets.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ func validatePluggableWidgetProperties(w *ast.WidgetV3, registry *WidgetRegistry
12711271
// Recognized real property the .def.json doesn't map to a write path:
12721272
// don't reject it as unknown, but be honest that a non-default value
12731273
// won't persist through mxcli yet (issue #643).
1274-
if knownUnmapped[lower] && persistedByExplicitPass(def.WidgetID, lower) {
1274+
if knownUnmapped[lower] && persistedByExplicitPass(def.WidgetID, lower, registryProjectPath(registry)) {
12751275
continue
12761276
}
12771277
if knownUnmapped[lower] {

0 commit comments

Comments
 (0)