|
| 1 | +-- mendixlabs/mxcli#1032 — `SET DataSource = DATABASE …` silently wiped a |
| 2 | +-- DataView's datasource |
| 3 | +-- |
| 4 | +-- The reported statement |
| 5 | +-- |
| 6 | +-- ALTER PAGE Test.MyPage { SET DataSource = DATABASE Test.Customer ON dvCust; }; |
| 7 | +-- |
| 8 | +-- passed `check`, ran to `Altered page …` with exit 0, and left the DataView |
| 9 | +-- with no usable datasource at all. `DESCRIBE PAGE` read the widget back as |
| 10 | +-- `dataview dvCust {` with the property gone, and the only other signal was |
| 11 | +-- CE7007 at build time — naming the widget, never the statement that broke it. |
| 12 | +-- |
| 13 | +-- Cause: one mapping standing in for several. A DATABASE source has no single |
| 14 | +-- stored shape; the widget holding it decides which element Studio Pro writes — |
| 15 | +-- Forms$ListViewXPathSource on a list view, CustomWidgets$CustomWidgetXPathSource |
| 16 | +-- on a pluggable widget, Forms$GridXPathSource on a grid. A DATA VIEW has no |
| 17 | +-- database form at all: it binds to ONE object, which is why CREATE PAGE's own |
| 18 | +-- builder refuses that pairing. The mutator instead wrote a Forms$DataViewSource |
| 19 | +-- — the "data from context" source — with the entity in EntityRef and |
| 20 | +-- SourceVariable left null, which is neither shape and is why DESCRIBE (whose |
| 21 | +-- context reader needs a SourceVariable) rendered nothing. |
| 22 | +-- |
| 23 | +-- Measured on a real Mendix 11.13.0 app, two copies of the same project: |
| 24 | +-- |
| 25 | +-- with the fault mxcli check --references → "Check passed!" |
| 26 | +-- mxcli exec → "Altered page …", exit 0 |
| 27 | +-- describe page → dataview dvCust { … } (no source) |
| 28 | +-- mx check → 1 error, CE7007 at Data view 'dvCust' |
| 29 | +-- |
| 30 | +-- with the fix mxcli check --references → refused, exit 1 |
| 31 | +-- mxcli exec → refused, exit 1 |
| 32 | +-- describe page → datasource unchanged |
| 33 | +-- mx check → 0 errors |
| 34 | +-- |
| 35 | +-- The refusal lives once, in the mutator, so `check` (which dry-runs the SET |
| 36 | +-- against a throwaway copy of the stored document) and `exec` cannot disagree. |
| 37 | +-- It needs the document to know the widget's type, so it fires under `-p`; this |
| 38 | +-- file is therefore the PASSING shape, with the refused statements commented. |
| 39 | +-- |
| 40 | +-- Run: mxcli check mdl-examples/bug-tests/1032-alter-page-set-database-datasource.mdl |
| 41 | +-- mxcli exec mdl-examples/bug-tests/1032-alter-page-set-database-datasource.mdl -p app.mpr |
| 42 | + |
| 43 | +create module P1032; |
| 44 | +create persistent entity P1032.Customer (Name: String(200)); |
| 45 | + |
| 46 | +create microflow P1032.MF_GetCustomer () returns P1032.Customer as $Result |
| 47 | +begin |
| 48 | + retrieve $Result from P1032.Customer limit 1; |
| 49 | +end; |
| 50 | + |
| 51 | +create page P1032.CustomerPage ( |
| 52 | + params: { $Customer: P1032.Customer }, |
| 53 | + title: 'Customer', |
| 54 | + layout: Atlas_Core.Atlas_Default |
| 55 | +) { |
| 56 | + layoutgrid g { row r { column c (desktopwidth: 12) { |
| 57 | + -- A LIST VIEW is where a database query belongs. Authored here through |
| 58 | + -- CREATE PAGE, which builds the Forms$ListViewXPathSource the widget needs. |
| 59 | + listview lvCustomers (datasource: database P1032.Customer) { |
| 60 | + textbox tbListName (attribute: Name, label: 'Name') |
| 61 | + } |
| 62 | + -- The DataView from the report, on a microflow source. |
| 63 | + dataview dvCust (datasource: microflow P1032.MF_GetCustomer) { |
| 64 | + textbox tbName (attribute: Name, label: 'Name') |
| 65 | + } |
| 66 | + } } } |
| 67 | +} |
| 68 | + |
| 69 | +-- The sources a DataView really takes still retype through SET, unchanged by |
| 70 | +-- the refusal — the control that says this fixes #1032 rather than replacing it |
| 71 | +-- with a blanket "no". |
| 72 | +alter page P1032.CustomerPage { |
| 73 | + set DataSource = $Customer on dvCust; |
| 74 | +} |
| 75 | + |
| 76 | +alter page P1032.CustomerPage { |
| 77 | + set DataSource = microflow P1032.MF_GetCustomer on dvCust; |
| 78 | +} |
| 79 | + |
| 80 | +alter page P1032.CustomerPage { |
| 81 | + set DataSource = selection lvCustomers on dvCust; |
| 82 | +} |
| 83 | + |
| 84 | +-- REFUSED, both by `check -p --references` and by `exec` (uncomment to see): |
| 85 | +-- |
| 86 | +-- alter page P1032.CustomerPage { |
| 87 | +-- set DataSource = database P1032.Customer on dvCust; |
| 88 | +-- } |
| 89 | +-- |
| 90 | +-- a data view cannot take a database datasource — a data view binds to a |
| 91 | +-- single object, so its source is a context parameter (`$Param`), a |
| 92 | +-- microflow, a nanoflow or `selection <widget>`; to show the result of a |
| 93 | +-- database query, use a list view or a data grid instead |
| 94 | +-- |
| 95 | +-- The same statement against the LIST VIEW is refused too, but for the other |
| 96 | +-- reason and with the other remedy — a list view can hold a database source, |
| 97 | +-- SET just cannot build one, so the message names the path that can: |
| 98 | +-- |
| 99 | +-- alter page P1032.CustomerPage { |
| 100 | +-- set DataSource = database P1032.Customer on lvCustomers; |
| 101 | +-- } |
| 102 | +-- |
| 103 | +-- setting a database datasource on "lvCustomers" (Forms$ListView) is not |
| 104 | +-- supported by `set` — its stored shape depends on the widget and is built |
| 105 | +-- by the CREATE PAGE path; use `replace <widget> with …` instead, which |
| 106 | +-- rebuilds the widget through that path |
0 commit comments