Skip to content

Commit 1ce7010

Browse files
akoclaude
andcommitted
fix(pages): conditional-settings Attribute is "" not null — fixes 11.12 load failure
A page whose widget carries a conditional visibility/editability setting failed to LOAD on Mendix 11.12 with a StorageLoadException: Conditional editability settings ... has an invalid value '' for property Attribute. The text ' ' is not a valid AttributeIdentifier. (the ' ' is \x03\x00\x00\x00, an int32 list marker; sometimes the mis-read value is the object's own $Type string). Both engines; the 11.12 nightly failed 03-page-examples this way. Root cause: mxcli serialized Forms$ConditionalVisibilitySettings / ConditionalEditabilitySettings `Attribute` as BSON null when there is no attribute-based condition. Studio Pro writes the empty string "" there (Attribute is a BY_NAME AttributeIdentifier). Mendix <= 11.11 tolerated the null; 11.12's stricter streaming reader rejects it and mis-aligns the following bytes. Found by comparing a Studio-Pro-authored settings node (str "") against mxcli's (NoneType) — the on-disk corruption is invisible to a naive decoder, which is why it looked (wrongly) like the harness's `mx update-widgets` step was to blame. Fix: emit Attribute "" not null. - legacy: serializeConditionalVisibility / serializeConditionalEditability. - modelsdk: new codec.TypeDefaults.EmptyStringFields; move "Attribute" from NullFields to EmptyStringFields for both settings types. Verified with the doctype gate: 03-page-examples passes on Mendix 11.12 AND 10.24 (both engines); no regression across 17/29/30/31/32/33. Repro: mdl-examples/bug-tests/conditional-settings-attribute-empty-1112.mdl. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0d1781c commit 1ce7010

6 files changed

Lines changed: 59 additions & 9 deletions

File tree

‎.claude/skills/fix-issue.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ to the symptom table below, so the next similar issue costs fewer reads.
101101
| `mxcli oql` against a docker-deployed app returns **0 rows** for tables that clearly have data (false negative — tester concluded "saving is broken") | NOT a database-config problem (that's a red herring — proven: aligning the runtime to Postgres with data still returned 0). The OQL preview servlet (`/dev/preview_execute_oql`) is registered by `com.mendix.basis.livepreview.LivePreviewRegistry` → `AppContainer.addDevelopmentServlet`, which **only mounts the servlet when the JVM system property `mendix.running.locally.by.studiopro=true` is set** (Studio Pro sets it; a deployed `bin/start` PAD doesn't). Without it the endpoint returns HTTP 200 `{"result":-5,"message":"Action not found"}`, which mxcli silently parsed as empty data. (Found by decompiling `com.mendix.mxruntime.jar` / `com.mendix.appcontainer.jar`.) | `cmd/mxcli/docker/templates/docker-compose.yml` (the `command`) + `cmd/mxcli/docker/oql.go` (`oqlDevError`) | Add `-J -Dmendix.running.locally.by.studiopro=true` to the start command (each JVM opt needs its own `-J`), next to the existing `-Dmendix.live-preview=enabled` — this mounts the dev servlets and `mxcli oql` returns live data (verified end-to-end; DTAP mode is NOT required, DB config is irrelevant — the preview runs in-process against the runtime DataStore). Separately, make `oqlDevError` surface `{"result":<0,"message":…}` (not just `{"error":…}`) so the failure isn't swallowed as 0 rows. **Related startup bug found:** the generated `etc/Default` inherits the project's ports, which are `0` when unset → the runtime rejects port 0 and won't start; `patchRuntimePorts` (patch.go) forces `runtime.http { port = 8080 }` / `admin { port = 8090 }`. Verified with a full docker build/run/seed cycle |
102102
| `GRANT VIEW ON PAGE Module.Page TO Module.Role` prints success but the page's allowed roles appear to stay empty: `mxcli lint` still reports `CE0557`/`MPR007` ("used as home page … but has no allowed roles") across a freshly rebuilt catalog, while entity-access grants on the same roles verify fine (`describe entity` shows them). Reported on **modelsdk** engine (default), Mendix 11.11 | NOT a write bug — the grant **does** persist (`AllowedModuleRoles: [3, "Module.Role"]` on disk; `mx check` = 0 errors; Studio Pro would load clean). The regression was on the **read** path: modelsdk `pageFromGen` didn't populate `Page.AllowedRoles`, and `mxcli lint`'s CE0557 rule counts `len(pg.AllowedRoles)` from `ListPages()` — so it read every page as having zero roles and false-fired. `SHOW ACCESS ON PAGE` / `SHOW SECURITY MATRIX` under-reported the same way. The entity-vs-page asymmetry the reporter saw = different read paths (entity `describe` worked; page `lint` didn't), not different writes | `mdl/backend/modelsdk/page.go` → `pageFromGen` | Already fixed by `88a2d50b1` (issue #722): populate `out.AllowedRoles` from the gen `AllowedRolesQualifiedNames()`, mirroring `microflowFromGen`. Guard for the reporter's exact end-to-end flow: `TestUpdateAllowedRoles_PagePersistsForLintRead` (`mdl/backend/modelsdk/page_roles_test.go`) writes a page role then reopens fresh and asserts the lint read path (`ListPages`→`AllowedRoles`) sees it. **Diagnosis tip**: when a write "reports success but the value stays empty" *only in a read/lint/show command*, dump the raw unit (`mxcli bson dump`) — if the bytes are there, it's a read-adapter (`*FromGen`) gap, not a write bug; confirm by reverting the suspected read commit and re-running |
103103
| `MOVE ENTITY X to OtherModule` where a **view entity's OQL** joins through `X`: passes `mxcli check`, but `mx check` on **Mendix 10.x** reports `CE0174 "…path '…/DmTest.Customer' does not resolve to an entity"` at the view entity — **only on the modelsdk engine**, only on 10.x (11.x is clean; legacy is clean) | Mendix <11 stores a view entity's OQL in **two** places: the top-level `DomainModels$ViewEntitySourceDocument` unit AND inline on the entity's `DomainModels$OqlViewEntitySource` (see `entityToGen`, gated `major < 11`). modelsdk's `UpdateOqlQueriesForMovedEntity` rewrote only the source document, leaving the inline copy pointing at the old module. 11.x doesn't write the inline copy (OQL lives only on the source doc), so it was never affected — hence 10.x-only. Legacy updates the inline copy incidentally by re-serializing the domain model | `mdl/backend/modelsdk/move_view_write.go` → `UpdateOqlQueriesForMovedEntity` | After the ViewEntitySourceDocument sweep, also iterate every domain model (`ListDomainModels` → `loadDomainModelGen`), find each entity whose `Source()` is `*genDm.OqlViewEntitySource` with an `Oql()` containing the old qualified name, `SetOql(strings.ReplaceAll(...))`, and `persistDM`. Mirrors the `UpdateEnumerationRefsInAllDomainModels` walk. **Diagnosis tip**: when a value updates in one storage location but a stale copy elsewhere still breaks `mx check`, dump raw `mprcontents` and grep for the value across `$Type`s — Mendix often duplicates a field (OQL, captions) and a version gate (`major < 11`) can make one copy version-conditional. Repro: `mdl-examples/bug-tests/move-entity-oql-view-inline-ref.mdl` |
104+
| A page whose widget has a **conditional visibility/editability** setting fails to **load** on **Mendix 11.12** — `StorageLoadException: Conditional editability settings … has an invalid value '' for property Attribute. The text ' ' is not a valid AttributeIdentifier` (the `' '` is `\x03\x00\x00\x00` = an int32 list marker; sometimes the value is the object's own `$Type` string). **Both engines**, ≤ 11.11 tolerated it. Reproduces only in the full doctype gate, not minimally — a red herring: it looked like `mx update-widgets` (harness step) was the cause, but the corruption is on disk from mxcli. My pymongo scans missed it because the value is a non-string type / the reader mis-parses | mxcli serialized `Forms$ConditionalVisibilitySettings` / `ConditionalEditabilitySettings` `Attribute` as **BSON null** when there's no attribute-based condition. Studio Pro writes the **empty string `""`** (Attribute is a BY_NAME `AttributeIdentifier`). 11.12's stricter streaming reader rejects the null and mis-reads the following bytes. Found by comparing a Studio-Pro-authored settings node (`str ""`) against mxcli's (`NoneType`) | legacy: `sdk/mpr/writer_widgets.go` (`serializeConditionalVisibility`/`serializeConditionalEditability`); modelsdk: `mdl/backend/modelsdk/widget_write.go` (RegisterTypeDefaults) + new `codec.TypeDefaults.EmptyStringFields` | Emit `Attribute: ""` not null. Legacy: change the `bson.D` value. Modelsdk: move `"Attribute"` from `NullFields` to the new `EmptyStringFields` (encoder emits `""`). **Diagnosis pattern**: when mx reports a corrupt value that pymongo *can't see on disk*, and the value looks like a `$Type` string or `\x03\x00\x00\x00`, suspect a wrong BSON *type* for a field (null where a string is required) that the streaming reader mis-aligns — compare field types against a Studio-Pro-authored node, don't just compare key presence. Repro: `mdl-examples/bug-tests/conditional-settings-attribute-empty-1112.mdl` |
104105
| A CLOSE PAGE microflow/nanoflow activity (`close page;`) fails `mx check` on **Mendix 11.12** with `CE0117 "Error(s) in expression"` at the Close page activity — **legacy engine only** (modelsdk passes; ≤ 11.6 tolerated it). Any annotation (`@caption`/`@color`/`@position`) on the activity reliably exposes it | The legacy `sdk/mpr` writer serialized the `Microflows$CloseFormAction` page-count under the field name `NumberOfPagesToClose`, but the metamodel storage name is `NumberOfPages` (the codec/modelsdk already used it — found by diffing the two engines' BSON: `legacy=NumberOfPagesToClose, modelsdk=NumberOfPages`). 11.12 doesn't recognise the old name, so the real `NumberOfPages` field is absent → defaults to an empty expression → CE0117 | `sdk/mpr/writer_microflow_actions.go` (`*microflows.ClosePageAction` case) + `sdk/mpr/parser_microflow_actions.go` | Write `NumberOfPages` (not `NumberOfPagesToClose`); the reader accepts both (`NumberOfPages` first, legacy `NumberOfPagesToClose` fallback) for round-trip fidelity on existing projects. **Diagnosis pattern**: a CE that says "invalid/empty expression" on an activity with no visible expression usually means a *renamed/missing* field defaulting to empty — diff the passing engine's BSON against the failing one to spot the field-name drift. Repro: `mdl-examples/bug-tests/close-page-numberofpages-1112.mdl` |
105106
| On **Mendix 11.12**, `mx check` fails to load projects on the **legacy** engine for several doctypes (`01-domain-model`, `10-odata`, `14-project-settings`, `22-published-rest`) with `System.InvalidOperationException: Expected '$ID' as the first property of a storage object, but got 'X'` at `StreamingBsonUnitReader`. The bad first-key varies run-to-run (`ThemeModuleOrder`, `EnableRspackBundler`, `Oql`, `MarkAsUsed`, `PopupResizable`…) — the tell-tale of random map-key order. modelsdk passes; ≤ 11.11 tolerates any order | Several legacy `sdk/mpr` writers preserve round-trip fidelity by carrying parsed subtrees as Go maps (`ProjectSettings.RawParts`, ref-marking `raw`, rename `raw`, domain-model `raw`) and marshalling them back. `bson.Marshal` emits **map keys in random order**, so `$ID` only lands first by luck. 11.12 rejects any storage object whose first key isn't `$ID`. The earlier `$ID`-first fix (bson.D reorder in writer_domainmodel/security) missed every map-passthrough site | `sdk/mpr/writer_settings.go` (+ `writer_refs`, `writer_rename`, `writer_domainmodel`, `writer_odata`, `writer_rest`, `writer_customblob`, `writer_security`, `writer_modules`, `writer_microflow`, … — all unit-boundary marshals) via new `sdk/mpr/writer_order.go` | Wrap every unit-boundary `bson.Marshal(doc)` in `marshalUnitIDFirst(doc)` = `bson.Marshal(bsonutil.HoistStorageID(doc))`. **Use the non-sorting `HoistStorageID`, NOT `OrderStorageValue`**: `OrderStorageValue` *sorts* the non-`$ID` keys, which corrupts template-derived pluggable-widget/datagrid page trees (mx then aborts with `got 'LabelTemplate'`, regressing `29-datagrid`/`33-alter-page`). `HoistStorageID` only lifts `$ID`/`$Type` to the front and preserves every other key's order → no-op on already-correct writers, fixes only the map-passthrough ones. **Do NOT normalize `writer_pages.go` or the page/workflow mutators** — their output is already `$ID`-first and they embed delicate widget maps the hoist would sort-corrupt. Verify on 11.12 with the doctype gate; regression-check `29`/`33` specifically. (Left unfixed: `03-page` LabelTemplate — a separate pre-existing issue where on-disk bytes read `$ID`-first yet mx still objects) |
106107
| A `NUMBERFILTER` in a DataGrid column passes `mxcli check` but corrupts the `.mpr`: MxBuild / Studio Pro **fails to load** the whole project on **Mendix 11.12** with `System.InvalidOperationException: Type …CustomWidgets.WidgetProperty does not contain a constructor with a parameter of type …CustomWidgets.WidgetValue` at `StreamingBsonUnitReader.ConstructObject`. `TEXTFILTER`/`DATEFILTER`/`DROPDOWNFILTER` in identical grids load fine; ≤ 11.11 loads even the number filter. Isolating it needs dropping widgets one-by-one under `mx check` | The embedded `datagrid-number-filter.json` template authored its 3 placeholder / screen-reader `Forms$ClientTemplate` blocks with **markerless empty arrays** — `"Items": []` and `"Parameters": []`. Every Mendix list serializes with a leading marker int (`Texts$Text.Items`→`[3]`, `ClientTemplate.Parameters`→`[2]`, `Widgets`/`Objects`→`[2]`); a bare `[]` has no marker. 11.12's stricter streaming reader mis-parses the markerless array and mis-associates the following bytes, so a nested `WidgetValue` lands where the reader is constructing a `WidgetProperty`. The template shape is otherwise identical to the working filters — the only diff is the missing markers (the blocks had hand-authored `dd2b3c4d…` placeholder IDs, i.e. not cleanly extracted from Studio Pro) | `sdk/widgets/templates/mendix-11.6/datagrid-number-filter.json` **and** `modelsdk/widgets/templates/mendix-11.6/datagrid-number-filter.json` (both engines embed their own copy) | Add the marker int to every empty `TextTemplate` array: `"Items": []`→`"Items": [3]`, `"Parameters": []`→`"Parameters": [2]`. Rebuild (`go:embed`), re-exec, verify with `scripts/mx-check.sh --version 11.12.0` (0 errors; regression-check 11.9 still clean). Guard: `TestTemplates_NoMarkerlessEmptyArrays` (in both `sdk/widgets` and `modelsdk/widgets`) walks every embedded template and fails on any bare `[]` — a Mendix list must always carry its marker. Repro: `mdl-examples/bug-tests/datagrid-numberfilter-array-marker.mdl`. **Diagnosis tip**: when a widget "passes check, fails 11.12 load" with the WidgetProperty/WidgetValue constructor error, suspect a markerless empty array in the template (shape-diff the failing widget's template against a working sibling; the smoking gun is `[]` vs `[<int>]`) |
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- Bug: a widget with a conditional visibility/editability setting failed to LOAD
2+
-- on Mendix 11.12 with a StorageLoadException — "Conditional editability settings
3+
-- ... has an invalid value '' for property Attribute. The text ' ' is not a valid
4+
-- AttributeIdentifier." (the 11.12 nightly failed 03-page-examples on both engines).
5+
--
6+
-- Root cause: mxcli serialized the ConditionalVisibilitySettings /
7+
-- ConditionalEditabilitySettings Attribute property as BSON null when there is no
8+
-- attribute-based condition. Studio Pro writes the empty string "" there (Attribute
9+
-- is a BY_NAME AttributeIdentifier). Mendix <= 11.11 tolerated the null; 11.12's
10+
-- stricter streaming reader rejects it (the null mis-reads as the object's own $Type
11+
-- string / an int32 list marker). Fix: emit "" — legacy writer, and a codec
12+
-- EmptyStringFields default for the modelsdk engine.
13+
--
14+
-- Verify in Studio Pro (11.12): the page must load and check without a
15+
-- StorageLoadException on the conditional properties.
16+
17+
create entity MyFirstModule.Cust ( Name: string(50), Phone: string(20) );
18+
19+
create microflow MyFirstModule.DS_GetCust ()
20+
returns MyFirstModule.Cust as $First
21+
begin
22+
retrieve $First from MyFirstModule.Cust limit 1;
23+
return $First;
24+
end;
25+
26+
create page MyFirstModule.P_Conditional ( title: 'Conditional', layout: Atlas_Core.Atlas_Default )
27+
{
28+
dataview dv (datasource: microflow MyFirstModule.DS_GetCust) {
29+
textbox txtName (label: 'Name', attribute: Name, visible: [$currentObject/Name != empty])
30+
textbox txtPhone (label: 'Phone', attribute: Phone, editable: [true])
31+
}
32+
};

‎mdl/backend/modelsdk/widget_write.go‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ func init() {
5656
codec.RegisterListMarker("Forms$Title", 2)
5757
// Conditional visibility/editability settings (issue #627). When a widget
5858
// carries one, applyWidgetBase emits the node; these defaults fill the
59-
// sub-fields Studio Pro writes: null Attribute/SourceVariable and empty
60-
// (marker-3) Conditions/ModuleRoles lists. Expression/IgnoreSecurity are set
61-
// from the model. ExpressionModel is intentionally omitted (legacy omits it).
59+
// sub-fields Studio Pro writes: empty-string Attribute, null SourceVariable, and
60+
// empty (marker-3) Conditions/ModuleRoles lists. Expression/IgnoreSecurity are
61+
// set from the model. ExpressionModel is intentionally omitted (legacy omits it).
62+
// Attribute is "" (not null): it is a BY_NAME AttributeIdentifier and Mendix
63+
// 11.12's reader rejects a null there (StorageLoadException, "not a valid
64+
// AttributeIdentifier").
6265
codec.RegisterTypeDefaults("Forms$ConditionalVisibilitySettings", codec.TypeDefaults{
63-
NullFields: []string{"Attribute", "SourceVariable"},
64-
MandatoryLists: []string{"Conditions", "ModuleRoles"},
66+
NullFields: []string{"SourceVariable"},
67+
EmptyStringFields: []string{"Attribute"},
68+
MandatoryLists: []string{"Conditions", "ModuleRoles"},
6569
})
6670
codec.RegisterTypeDefaults("Forms$ConditionalEditabilitySettings", codec.TypeDefaults{
67-
NullFields: []string{"Attribute", "SourceVariable"},
68-
MandatoryLists: []string{"Conditions"},
71+
NullFields: []string{"SourceVariable"},
72+
EmptyStringFields: []string{"Attribute"},
73+
MandatoryLists: []string{"Conditions"},
6974
})
7075
// A caption parameter's AttributeRef/SourceVariable are null for the literal-
7176
// expression form; populated Parameters lists use marker 2.

‎modelsdk/codec/defaults.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ type TypeDefaults struct {
2828
// NullFields are keys Studio Pro always serializes as BSON null (e.g. an
2929
// unset reference like an association's Source); emitted when not otherwise set.
3030
NullFields []string
31+
// EmptyStringFields are keys Studio Pro always serializes as the empty string ""
32+
// (not null) when unset — e.g. a ConditionalVisibility/EditabilitySettings'
33+
// Attribute (a BY_NAME AttributeIdentifier). Mendix 11.12's reader rejects a
34+
// null there. Emitted as "" when not otherwise set.
35+
EmptyStringFields []string
3136
// ZeroGUIDFields are reference keys Studio Pro serializes as an all-zero GUID
3237
// binary when the reference is unset (e.g. an IndexedAttribute's
3338
// AssociationPointer on an attribute-based index segment). Emitted when not

‎modelsdk/codec/encoder.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ func (e *Encoder) buildDoc(elem element.Element) (bson.D, error) {
176176
doc = append(doc, bson.E{Key: name, Value: nil})
177177
}
178178
}
179+
for _, name := range d.EmptyStringFields {
180+
if !emitted[name] {
181+
doc = append(doc, bson.E{Key: name, Value: ""})
182+
}
183+
}
179184
for _, name := range d.ZeroGUIDFields {
180185
if !emitted[name] {
181186
doc = append(doc, bson.E{Key: name, Value: zeroGUIDBinary()})

‎sdk/mpr/writer_widgets.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ func serializeConditionalVisibility(cvs *pages.ConditionalVisibilitySettings) bs
136136
return bson.D{
137137
{Key: "$ID", Value: idToBsonBinary(string(cvs.ID))},
138138
{Key: "$Type", Value: "Forms$ConditionalVisibilitySettings"},
139-
{Key: "Attribute", Value: nil},
139+
// Attribute is a BY_NAME AttributeIdentifier; Studio Pro writes "" (not null)
140+
// when there is no attribute-based condition. 11.12's reader rejects the null.
141+
{Key: "Attribute", Value: ""},
140142
{Key: "Conditions", Value: bson.A{int32(3)}},
141143
{Key: "Expression", Value: cvs.Expression},
142144
{Key: "IgnoreSecurity", Value: false},
@@ -149,7 +151,7 @@ func serializeConditionalEditability(ces *pages.ConditionalEditabilitySettings)
149151
return bson.D{
150152
{Key: "$ID", Value: idToBsonBinary(string(ces.ID))},
151153
{Key: "$Type", Value: "Forms$ConditionalEditabilitySettings"},
152-
{Key: "Attribute", Value: nil},
154+
{Key: "Attribute", Value: ""}, // "" not null — see serializeConditionalVisibility
153155
{Key: "Conditions", Value: bson.A{int32(3)}},
154156
{Key: "Expression", Value: ces.Expression},
155157
{Key: "SourceVariable", Value: nil},

0 commit comments

Comments
 (0)