Skip to content

Commit 5071aa4

Browse files
authored
Merge pull request #452 from ako/claude/mxbuild-diagnostics-spike-emta6h
View entities and widget bodies: three defects from ako/view-entity-examples
2 parents c79e0b4 + c6d0e25 commit 5071aa4

33 files changed

Lines changed: 2459 additions & 128 deletions

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

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

‎.claude/skills/mendix/custom-widgets/SKILL.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@ The error now names the container keyword and rewrites your entry into the form
7272
that works.
7373

7474
`describe widget <name> -p <project.mpr>` lists a widget's container keywords
75-
under **Body containers**.
75+
under **Body containers**, and — for an object list — the widgets-typed **slots
76+
inside one item**, with the widget types that route into each:
77+
78+
```
79+
column object list -> columns authorable
80+
items: showContentAs, attribute, dynamicText, …
81+
slot content -> content: any other widget in the item body
82+
slot filter -> filter: textfilter | numberfilter | datefilter | dropdownfilter
83+
```
84+
85+
Read that last line before guessing where something goes. It says a Data Grid 2
86+
column filter is written directly in the **column's** braces — not in
87+
`controlbar`, which is the grid-wide filter bar and renders "Unable to get
88+
filter store" if you put a column filter there.
7689

7790
### When the name is not found
7891

‎.claude/skills/mendix/overview-pages/SKILL.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ column colStatus (attribute: "Status") { dropdownfilter f4 } -- Enumeration
214214
-- Boolean columns: omit the filter entirely
215215
```
216216
217+
**The filter goes inside the column's own braces.** A `filter { … }` block is
218+
the GALLERY spelling of a different thing — the widget-wide filter bar, which a
219+
data grid calls `controlbar`:
220+
221+
```sql
222+
-- ✅ data grid: per-column filter, inside the column
223+
datagrid dg (...) { column colName (attribute: Name) { textfilter f1 } }
224+
225+
-- ✅ gallery: the widget-wide filter bar, which the gallery calls `filter`
226+
gallery g (...) { filter f { textfilter f1 } }
227+
228+
-- ❌ the gallery form on a data grid — MDL-WIDGET30
229+
datagrid dg (...) { column colName (attribute: Name) filter f { textfilter f1 } }
230+
```
231+
232+
That last line is worth reading twice: it is not a column with a filter block.
233+
A widget is `type name (props) { body }`, so with the `filter` *outside* the
234+
column's braces it parses as a column with **no body** followed by a separate
235+
`filter` widget — which the grid has nowhere to put. It used to be dropped on
236+
write with no diagnostic, so `DESCRIBE PAGE` showing a filterless column was the
237+
only symptom; it is now refused at check and exec time.
238+
217239
## NewEdit Page Template
218240

219241
Form for creating or editing a single entity. **Requires a page parameter** to receive the object.

‎.claude/skills/mendix/write-oql-queries/SKILL.md‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,75 @@ create view entity Module.ViewName (
349349
);
350350
```
351351

352+
### Step 1b: Know the two clause orders
353+
354+
Mendix OQL accepts the select list in either position, and mxcli reads both:
355+
356+
```sql
357+
-- Select-first. Write new views this way; the rest of this skill assumes it.
358+
select c.Name as Name, count(o.ID) as Orders
359+
from Shop.Customer as c
360+
group by c.Name
361+
362+
-- From-first. Same query. This is what STUDIO PRO STORES, so it is what
363+
-- `describe entity` gives you back — copy it, edit it, exec it unchanged.
364+
from Shop.Customer as c
365+
group by c.Name
366+
select c.Name as Name, count(o.ID) as Orders
367+
```
368+
369+
Note where `group by` sits: in the from-first order every clause except
370+
`order by` / `limit` comes **before** the select list, and the grammar enforces
371+
that. `from … select … group by …` is a parse error, not a variant.
372+
373+
Do not rewrite a described view into select-first just to make it look
374+
familiar — the stored text is what MxBuild validates against, and a needless
375+
rewrite is a diff for nothing.
376+
377+
### Step 1c: Selecting an id makes an ASSOCIATION, not an attribute
378+
379+
Selecting a persistent entity's `ID` under an alias gives the view entity an
380+
association to that entity. The alias becomes the association's name, and the
381+
column is **not** one of the view entity's attributes — so do not declare one
382+
for it:
383+
384+
```sql
385+
create view entity Sales.OrdersVE (
386+
order_date: DateTime -- one attribute…
387+
) as (
388+
from Sales."Order" as o
389+
select o.ID as persistent_order -- …but two columns
390+
, o.OrderDate as order_date
391+
);
392+
```
393+
394+
mxcli creates the association member from that column. There is no separate
395+
statement for it, and `create association` with a view entity at either end is
396+
refused — Mendix rejects it (CE6771), because the association needs an
397+
`OqlViewAssociationSource` that a plain one does not have.
398+
399+
Two rules:
400+
401+
- **The alias must be free in the module, case-insensitively.** It is the
402+
association's name, and Mendix reports *"Duplicate name 'Meter' in module
403+
'Trends'. Entities, associations and enumerations cannot share names."* So
404+
`as meter` beside an entity called `Meter` fails — name it `MeterRef`.
405+
- **Reach the target through a join if it is not the FROM entity**, and select
406+
the id off *that* alias: `join r/Trends.Reading_Meter/Trends.Meter as m … select m.ID as MeterRef`.
407+
408+
**Consider the flat alternative first.** An association costs a second query at
409+
runtime — the view returns the foreign key, and the client then fetches the
410+
referenced objects in a batched `IN (...)` per page, materialising real objects
411+
in its state. Selecting a string copy instead is one statement, one join, no
412+
second retrieve, and the id is still there to look the object up with:
413+
414+
```sql
415+
select cast(m.ID as string) as MeterId, m.MeterCode as MeterCode, …
416+
```
417+
418+
Use the association when you want to bind widgets over it (`MeterRef/MeterCode`);
419+
use the cast when you just need the value.
420+
352421
### Step 2: Write SELECT Clause
353422
- Use **lowercase** aggregate functions: `sum()`, `avg()`, `count()`
354423
- Use `count(entity.ID)` not `count(*)`

‎cmd/mxcli/syntax/features_page.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,16 @@ CREATE PAGE Sales.Detail (Title: 'Detail', Layout: Atlas_Core.Atlas_Default) {
124124
},
125125
Syntax: "-- Containers\nLAYOUTGRID name { ROW r { COLUMN c (DesktopWidth: 6) { ... } } }\nCONTAINER name (Class: 'cls') { ... }\nCONTAINER name (OnClick: MICROFLOW Module.MF) { ... } -- clickable container\nCUSTOMCONTAINER name (Class: 'cls') { ... }\nGROUPBOX name (Caption: 'C') { ... }\nTABCONTAINER name { TABPAGE tp (Caption: 'One') { ... } TABPAGE tp2 (Caption: 'Two') { ... } }\n\n" +
126126
"-- Data widgets\nDATAVIEW name (DataSource: $Param) { ... FOOTER f { ... } }\nDATAGRID name (DataSource: DATABASE Module.Entity) { COLUMN c (Attribute: A) }\nGALLERY name (DataSource: DATABASE Module.Entity, DesktopColumns: 3) { ... }\nLISTVIEW name (DataSource: DATABASE Module.Entity) { ... }\nLISTVIEW name (...) { ... TEMPLATE FOR Module.Specialization { ... } }\n\n" +
127-
"-- Data grid filters and sort (inside a DATAGRID's FILTER block)\nDATAGRID dg (...) { COLUMN c (Attribute: A) FILTER f { TEXTFILTER tf (Attribute: A) } }\nTEXTFILTER | NUMBERFILTER | DATEFILTER | DROPDOWNFILTER | DROPDOWNSORT\n\n" +
127+
"-- Data grid 2 column filters go INSIDE the column's own braces\nDATAGRID dg (...) { COLUMN c (Attribute: A) { TEXTFILTER tf (Attribute: A) } }\nTEXTFILTER | NUMBERFILTER | DATEFILTER | DROPDOWNFILTER | DROPDOWNSORT\n" +
128+
"-- Match the filter to the column's type, or MxBuild refuses it: String ->\n" +
129+
"-- TEXTFILTER, Integer/Long/Decimal -> NUMBERFILTER, Date and time -> DATEFILTER,\n" +
130+
"-- Enumeration -> DROPDOWNFILTER. A Boolean column takes no filter at all.\n" +
131+
"-- The grid-wide filter bar is CONTROLBAR; a GALLERY spells that same slot\n" +
132+
"-- FILTER, so `FILTER f { ... }` belongs to a gallery and not to a datagrid:\n" +
133+
"GALLERY g (...) { FILTER f { TEXTFILTER tf (Attribute: A) } }\n" +
134+
"-- A FILTER block written on a DATAGRID is not a column filter and not a\n" +
135+
"-- container the grid declares — it used to be dropped on write with no\n" +
136+
"-- diagnostic, and is now refused (MDL-WIDGET30).\n\n" +
128137
"-- Inputs\nTEXTBOX name (Label: 'L', Attribute: Attr)\nTEXTAREA | DATEPICKER | COMBOBOX | CHECKBOX | RADIOBUTTONS\n\n" +
129138
"-- Actions\nACTIONBUTTON name (Caption: 'C', Action: SAVE_CHANGES, ButtonStyle: Primary)\nLINKBUTTON name (Caption: 'C', Action: ...)\n\n" +
130139
"-- Display\nDYNAMICTEXT name (Content: 'Hello, {1}!', ContentParams: [{1} = Name])\nTITLE name (Content: 'Heading')\nIMAGE name (Image: 'Module.Collection.ImageName')\nIMAGE name (ImageType: imageUrl, ImageUrl: 'https://…')\n" +
@@ -145,7 +154,7 @@ CREATE PAGE Sales.Detail (Title: 'Detail', Layout: Atlas_Core.Atlas_Default) {
145154
"-- DROPDOWN -> COMBOBOX\n" +
146155
"-- And three the executor refuses on BOTH engines, each with its own message:\n" +
147156
"-- STATICTEXT (writes Forms$Text, a type Mendix no longer has — the\n" +
148-
"-- project could not be OPENED afterwards; MDL-WIDGET29.\n" +
157+
"-- project could not be OPENED afterwards; MDL-WIDGET30.\n" +
149158
"-- Use DYNAMICTEXT with a literal Content.)\n" +
150159
"-- REFERENCESELECTOR (unsupported widget type)\n" +
151160
"-- LEGACYDATAGRID (use DATAGRID for the pluggable equivalent on Mendix 11+)",

‎docs-wiki/bug-patterns/silent-property-drop.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ writers → both readers → describe.
8383
that `check` rejected outright; a validator that no pass calls reports no
8484
violations and reads exactly like a clean project.
8585

86+
**The sharper version: a check can be switched off by its own input.** Where a
87+
family of rules hangs off one parsed fragment — a select clause, a resolved
88+
definition, a decoded sub-document — a parse that yields nothing does not report
89+
"I could not read this"; it reports nothing at all, which is the same output as
90+
a clean file. The view-entity OQL scanner did this twice, two months apart and
91+
in the same function: once because it compared cases wrongly, once because
92+
Mendix's other clause order put the terminator behind the keyword it scanned
93+
forward from. Both times a single visible false positive was the only hint,
94+
while three real rules stopped running behind it. The durable fix is not the
95+
next input shape, it is making *unreadable* a reported outcome distinct from
96+
*nothing to report* — after which a third shape costs a diagnostic rather than a
97+
blind spot.
98+
99+
**Children drop the same way properties do.** A widget's body is distributed by
100+
several passes that each skip what they do not recognise, so a child matching no
101+
container, no slot and no catch-all is built and discarded exactly as an
102+
unrouted property is. The compounding factor is that the *same slot* wears
103+
different keywords on different widgets — the filters placeholder is `filter` on
104+
a Gallery and `controlbar` on a Data Grid — so a form copied between two widgets
105+
is both plausible and inert. That table is also the fix: because the engine
106+
already maps keyword to property per widget, the diagnostic can name the
107+
spelling *this* widget uses instead of listing everything it declares.
108+
86109
## See also
87110

88111
- [fix-issue findings](../../.claude/skills/fix-issue/findings/) — the individual

‎docs/01-project/MDL_QUICK_REFERENCE.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ create persistent entity Module.Photo (
6262
| Create with extends | `create persistent entity Module.Name extends Parent.Entity (attrs);` | EXTENDS before `(` |
6363
| Create with auditing | `create persistent entity Module.Name (attrs, owner: autoowner, ChangedBy: autochangedby, CreatedDate: autocreateddate, ChangedDate: autochangeddate);` | Pseudo-types like AutoNumber |
6464
| Create view entity | `create view entity Module.Name (attrs) as select ...;` | OQL-backed read-only |
65+
| View entity clause order | `... as select … from …;` **or** `... as from … group by … select …;` | Both are Mendix OQL and both are checked. The second is what **Studio Pro stores**, so it is what `DESCRIBE ENTITY` emits — describe → edit → exec round-trips. The declared attributes are matched to the select columns **by position**, in either order |
66+
| View entity → persistent entity | `select t.ID as MyRef, …` in the OQL | Selecting the target's **id** under an alias gives the view entity an **association** named after the alias. It is not an attribute and gets no declaration: the column *is* the declaration, so mxcli creates the member (with the `OqlViewAssociationSource` mxbuild requires — without it, CE6771 + CE6770). A plain `create association` with a view entity at either end is **refused**. The alias must be free in the module, case-insensitively. `cast(t.ID as string) as MyId` is a plain String attribute instead — one query rather than two, no objects in the client |
6567
| Create external entity | `create external entity Module.Name from odata client Module.Client (...) (attrs);` | From consumed OData |
6668
| Create external entities | `create [or modify] external entities from Module.Client [into module] [entities (...)];` | Bulk from $metadata |
6769
| Drop entity | `drop entity Module.Name;` | |
@@ -1338,7 +1340,9 @@ MDL uses explicit property declarations for pages:
13381340
| Page CSS class / style | `Class: 'css-class', Style: 'css: rule'` | `(Title: 'Home', Class: 'container-fluid bg-light', Style: 'min-height: 100vh')` — the page's Appearance |
13391341
| Page variables | `variables: { $name: type = 'expr' }` | `variables: { $show: boolean = 'true' }` |
13401342
| Repeated widget entries | `<container> <name> ( … )` **in the widget body** | A repeatable property (FileUploader `allowedFileFormats`, HTML Element `attributes`, a chart's `series`) is a block, never a property value. `attributes: [(attributeName: 'x')]` is **MDL-WIDGET27** — it used to check clean, exec, and vanish from storage. `describe widget <name> -p app.mpr` lists the container keywords |
1341-
| Inspect a widget | `describe widget <keyword\|'widget id'>;` | `describe widget combobox;` — properties, enum values, defaults and the editor rules that HIDE properties under some configurations. Works with no project open; with one, reads the installed `.mpk` (version-accurate, and the only place a Marketplace widget appears). Same output as `mxcli widget describe` |
1343+
| Data grid 2 column filter | `column c (attribute: A) { textfilter f }` | **Inside the column's braces.** `column c (…) filter f { … }` is the GALLERY form — the grammar reads it as a column with no body plus a sibling `filter` widget, which the grid has nowhere to put; it used to be dropped on write and is now **MDL-WIDGET30**. A grid-wide filter bar is `controlbar`; a gallery spells that same slot `filter`. Match the filter to the column's type (String → `textfilter`, number → `numberfilter`, DateTime → `datefilter`, Enumeration → `dropdownfilter`, Boolean → none) |
1344+
| Widget with nowhere to go | any widget in a pluggable widget's body | A child matching no container, slot or `template` catch-all is **MDL-WIDGET30** at check time and refused by `exec`. `describe widget <name> -p app.mpr` lists what the parent declares. Needs the parent's definition, so it is silent without `-p` |
1345+
| Inspect a widget | `describe widget <keyword\|'widget id'>;` | `describe widget combobox;` — properties, enum values, defaults and the editor rules that HIDE properties under some configurations. **Body containers** names what the widget's body takes, and for an object list the widgets-typed slots *inside one item* plus the widget types that route into each — that is where `column … { textfilter }` is spelled out. Works with no project open; with one, reads the installed `.mpk` (version-accurate, and the only place a Marketplace widget appears). Same output as `mxcli widget describe` |
13421346
| Widget name | Required after type | `textbox txtName (...)` |
13431347
| Attribute binding | `attribute: AttrName` | `textbox txt (label: 'Name', attribute: Name)` |
13441348
| Variable binding | `datasource: $Var` | `dataview dv (datasource: $Product) { ... }` |
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
-- Bug: a widget written in a pluggable widget's body that the widget has
2+
-- nowhere to put was BUILT AND THROWN AWAY, with no diagnostic from `check`
3+
-- and no error from `exec`. `DESCRIBE PAGE` afterwards showing the widget gone
4+
-- was the only way to find out.
5+
--
6+
-- Reported by ako/view-entity-examples FINDINGS §2, as a Data Grid 2 filter.
7+
-- The form that vanished is the one `mxcli syntax page widgets` documented:
8+
--
9+
-- DATAGRID dg (...) { COLUMN c (Attribute: A) FILTER f { TEXTFILTER tf (...) } }
10+
--
11+
-- Two things are wrong with it, and only together do they hide:
12+
-- 1. `FILTER` is the GALLERY keyword for the filters placeholder. DataGrid 2
13+
-- spells the same property `controlbar` (widgetSlotKeywordOverrides).
14+
-- 2. `widgetV3` is `type name props? body?`, so `COLUMN c (…) FILTER f { … }`
15+
-- is a COLUMN WITH NO BODY followed by a SIBLING filter widget — nothing
16+
-- binds the second to the first. The sibling landed among the grid's own
17+
-- children, matched no container, and was dropped.
18+
--
19+
-- Root cause: the four passes that place a pluggable widget's children
20+
-- (applyChildSlots, applyObjectLists, and two auto-discovery passes) each
21+
-- `continue` past a child they do not recognise, and applyChildSlots parks
22+
-- the leftovers in `defaultWidgets` — which is assigned only if the widget
23+
-- declares a `template` slot. A Gallery has one; DataGrid 2 does not, so its
24+
-- leftovers were discarded. Not datagrid-specific: one `continue` per pass,
25+
-- shared by every pluggable widget.
26+
--
27+
-- Fix: MDL-WIDGET30 at check time and a refusal in buildPluggable at exec time,
28+
-- both from unroutedPluggableChildren() so they cannot disagree. The message
29+
-- names the spelling THIS widget uses for the same slot, since an author who
30+
-- copied a gallery example needs `controlbar`, not a list to search.
31+
--
32+
-- This repro is a plain .mdl, not .fail.mdl, on purpose: MDL-WIDGET30 needs the
33+
-- parent widget's DEFINITION, which comes from the project's installed .mpk, and
34+
-- `make check-mdl` runs `check` with no project (see the Makefile's note on
35+
-- #891/#892). The refusal is covered by widget_unrouted_children_test.go; this
36+
-- file records the working spellings so they stay working.
37+
--
38+
-- Reading the definition from the project's .mpk is also what keeps the rule
39+
-- current: Data Widgets ships DataGrid 2 in every Mendix 11 app, and upgrading
40+
-- that module from the Marketplace changes what mxcli sees with no mxcli release.
41+
--
42+
-- Measured end to end on Mendix 11.13.0, DataGrid 2 (Data Widgets) 3.4.0, with
43+
-- the guard stubbed as the control:
44+
-- guard stubbed, `exec --no-check` the FILTER form
45+
-- → "Created page", exit 0 … and `describe page` shows
46+
-- `column MeterCode (Attribute: MeterCode, Caption: 'Meter')` with NO
47+
-- filter. That is the reported defect: a success that lost the widget.
48+
-- guard in place, same script → refused, exit 1, naming `controlbar`
49+
-- guard in place, THIS file → "Replaced page", and `describe page` shows
50+
-- `column … { textfilter tf }` — it persisted
51+
-- mx check on the result → 0 errors
52+
53+
create module VFilterDrop;
54+
55+
create entity VFilterDrop.Meter (
56+
MeterCode: String(50),
57+
Readings: Integer,
58+
LastSeen: DateTime
59+
);
60+
61+
create page VFilterDrop.Meters (
62+
title: 'Meters',
63+
layout: Atlas_Core.Atlas_Default
64+
) {
65+
datagrid dgMeters (datasource: database VFilterDrop.Meter) {
66+
-- The working form: the filter goes INSIDE the column's own braces, and
67+
-- must match the column attribute's type.
68+
column colCode (attribute: MeterCode, caption: 'Meter') {
69+
textfilter fCode (attribute: MeterCode)
70+
}
71+
column colReadings (attribute: Readings, caption: 'Readings') {
72+
numberfilter fReadings (attribute: Readings)
73+
}
74+
column colSeen (attribute: LastSeen, caption: 'Last seen') {
75+
datefilter fSeen (attribute: LastSeen)
76+
}
77+
}
78+
}
79+
80+
-- Control: on a GALLERY the very same `filter { … }` block is correct — it is
81+
-- that widget's own keyword for the filters placeholder. A rule that simply
82+
-- banned the keyword would have broken this page, which is why the fix asks
83+
-- the parent's definition rather than matching on the word.
84+
create page VFilterDrop.MeterGallery (
85+
title: 'Meter gallery',
86+
layout: Atlas_Core.Atlas_Default
87+
) {
88+
gallery galMeters (datasource: database VFilterDrop.Meter, desktopcolumns: 3) {
89+
filter galFilter {
90+
textfilter fGalCode (attribute: MeterCode)
91+
}
92+
template galTemplate {
93+
dynamictext txtCode (content: '{1}', contentparams: [{1} = MeterCode])
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)