Skip to content

Commit a2cdc3c

Browse files
akoclaude
andcommitted
fix(view-entity): refuse an attribute that tries to hold an object (MDL080)
`select m.ID as MeterRef` gives a view entity an association named MeterRef. Declaring it in the attribute list as well — `MeterRef: Trends.Meter` or `MeterRef: Trends.Meter.ID` — parsed as an enumeration type and exec stored it as one. Measured on 11.14.0: CE1613 "The selected enumeration 'Trends.Meter' no longer exists", and for the three-part form mx check throws before validating anything. check passed it; check -p reported "1 columns but 2 attributes" and compared the attribute against the next column. - check, with no project (MDL080): a declared name that is an association column's alias, or a three-part type name. - check -p: an attribute typed with an entity under any other name, before the type comparison that misreported it. - exec: both, before any write, --no-check included (0 files changed). Reported in ako/view-entity-examples FINDINGS §4. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 68a5f29 commit a2cdc3c

10 files changed

Lines changed: 330 additions & 0 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
@@ -603,3 +603,4 @@
603603
{"area": "mdl/executor", "date": "2026-09-13", "symptom": "A PARALLEL SPLIT written from MDL passes `mxcli check`, builds at 0 errors and round-trips through `describe`, but at runtime every path runs from the split straight to its end: the activities inside never execute and leave no row in `system$workflowactivity` (only 'End of parallel split path' / 'Merge of Parallel split' records appear)", "cause": "Mendix stores an `EndOfParallelSplitPathActivity` as the last activity of every path and the engine executes a path up to it. mxcli wrote path flows without one, in `buildParallelSplit`, in both writers (neither serialized the type \u2014 both switches returned nil) and in both `InsertPath` mutators. The modelsdk reader also read the marker as a GenericWorkflowActivity, so a Studio Pro split described with a leaked `-- [Workflows$EndOfParallelSplitPathActivity]` comment", "file": "`sdk/workflows/workflow.go` (`EndParallelSplitPath`), `mdl/executor/cmd_workflows_write.go` (`buildParallelSplit`, `deduplicateActivityNamesInFlow`), `mdl/backend/modelsdk/workflow_write.go` + `workflow_read.go`, `sdk/mpr/writer_workflow.go`, `mdl/backend/wfmutator/mutator.go` + `mdl/backend/mcp/workflow.go` (`InsertPath`)", "insight": "**A symptom that lives in the running app can only be settled there, and an A/B instance is the cheapest way.** Booted once with two copies of the workflow differing only in a trailing marker written by an env-gated experiment, then read `system$workflowactivity` joined to the context object: without the marker neither path's microflow had a record, with it both finished \u2014 root cause and fix in one boot. Two traps followed. (1) The experiment gave each marker a unique name; the real fix gave them one name and built with CE0495, because `deduplicateActivityNamesInFlow` renames only the types its switch lists \u2014 every unit test on the shape was green and only mxbuild caught it, so re-run the build on the SHIPPED code, never trust the experiment's. (2) `describe` skips the marker by its semantic type, so it hid whether the marker existed at all \u2014 dump the BSON (`mxcli bson dump --type workflow --format ndsl`, or decode the .mxunit) when the describer is designed to omit the thing in question. Controls: reverting the builder call fails `TestBuildParallelSplitEndsEveryPath` with the path's real last activity; removing the marker types from the dedupe switch fails `TestDeduplicateNamesEndOfPathMarkers` with the duplicated name", "refs": ["ako/view-entity-examples FINDINGS \u00a76"]}
604604
{"area": "mdl/executor", "date": "2026-09-13", "symptom": "A boundary event path written from MDL fails the build with CE0105 'Call microflow cannot be the last object of a flow, it should end with a jump or end activity' (interrupting), or builds at 0 errors and the runtime refuses to start: 'Expected the flow to end with an end event' (non-interrupting). After the fix, `create or modify` of the same workflow was refused by the dropped-construct guard", "cause": "Mendix ends every boundary event path with `EndOfBoundaryEventPathActivity`; mxcli never wrote one, and MDL has no end statement. The rewrite guard then counted `$Type`s containing 'BoundaryEvent', which includes the marker, so a stored workflow with one event counted two", "file": "`sdk/workflows/workflow.go` (`EndBoundaryEventPath`), `mdl/executor/cmd_workflows_write.go` (`buildBoundaryEvents`), `mdl/backend/wfmutator/mutator.go` + `mdl/backend/mcp/workflow.go` (`InsertBoundaryEvent`), `mdl/executor/validate_workflow_rewrite.go` (`countRawBoundaryEvents`)", "insight": "**Same class as the parallel-split marker: a Studio Pro terminal marker that no MDL statement spells.** Grep the writers for every `EndOf*` type the reader knows before assuming one is the only one. The guard miscount was only visible by re-running the fixed script against the fixed workflow \u2014 a substring match on `$Type` is wrong the moment a sibling type shares the stem; match the suffix, and keep a control asserting the substring count so the test says why", "fix": "Append the marker unless the path ends in a jump or end-of-workflow (CE6692 otherwise); count boundary events by `strings.HasSuffix($Type, \"BoundaryEvent\")`"}
605605
{"area": "mdl/executor", "date": "2026-09-13", "symptom": "A workflow with `boundary event timer '\u2026'` (no interrupting / non interrupting) passes check and builds at 0 errors; the runtime then fails to start: `Class 'Workflows$TimerBoundaryEvent' could not be found`", "cause": "The bare form maps to `Workflows$TimerBoundaryEvent`, which exists in no cached 11.x runtime (only Interrupting/NonInterruptingTimerBoundaryEvent). mxbuild tolerates the unknown type. It was the documented syntax example", "file": "`mdl/executor/validate_workflow_refs.go` (`bareTimerBoundaryEventErrors`, MDL-WF07), `cmd/mxcli/syntax/features_workflow.go`", "insight": "**A type mxbuild accepts is not a type the runtime has.** Found only because a verification boot of an unrelated fix loaded it. When a grammar has a default branch that maps to a storage type, check that type against the runtime's class list, not against `mx check`", "fix": "Refuse the bare form on 11+ at check and exec, CREATE and every ALTER op that can carry a boundary event; update syntax help, skill table and the ako/mxcli#415 bug-test script to name the kind"}
606+
{"area": "mdl/executor", "date": "2026-09-13", "symptom": "A view entity whose association column is also declared as an attribute (`MeterRef: Trends.Meter` or `MeterRef: Trends.Meter.ID` beside `select m.ID as MeterRef`) passes `mxcli check`; `check -p` says 'OQL select has 1 columns but 2 attributes declared'; exec writes `Enumeration(Trends.Meter)` and mx check reports CE1613, or throws 'An error occurred when trying to set the Enumeration property' for the three-part form", "cause": "A bare qualified name parses as TypeEnumeration (the entity/enum ambiguity), and execCreateViewEntity converted it with convertDataType without asking what it names. The alias-to-attribute alignment skips association columns, so the declared attribute had no column and was compared against the next one", "file": "`mdl/executor/oql_view_associations.go` (`ValidateViewAttributeDeclarations` MDL080, `viewAttributeEntityTypeErrors`), `mdl/executor/cmd_entities.go` (`execCreateViewEntity`), `mdl/executor/validate.go`, `mdl/executor/validate_program.go`, `cmd/mxcli/lsp_diagnostics.go`", "insight": "**The TypeEnumeration/TypeEntity ambiguity has a consumer wherever a data type becomes a stored type, and view entity attributes were one nobody had listed.** Split the refusal by what it needs: an association column's alias and a three-part name are decidable from the script, so they belong in the no-project phase that exec's pre-check also runs; entity-vs-enum needs the project, so it goes in check -p AND the handler, because exec --no-check skips both phases. Verify the handler refusal by counting changed files, not by the error text", "fix": "Refuse in ValidateProgram/LSP (MDL080) and at the top of execCreateViewEntity before any backend call; report an attribute once"}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ Two rules:
404404
`as meter` beside an entity called `Meter` fails — name it `MeterRef`.
405405
- **Reach the target through a join if it is not the FROM entity**, and select
406406
the id off *that* alias: `join r/Trends.Reading_Meter/Trends.Meter as m … select m.ID as MeterRef`.
407+
- **Do not declare the id column as an attribute.** `MeterRef: Trends.Meter` (or
408+
`Trends.Meter.ID`) in the attribute list parses — a bare qualified name is how
409+
MDL spells an enumeration type — and would be stored as an enumeration naming
410+
an entity: CE1613 at build, or mx check failing to load the project. mxcli
411+
refuses it (MDL080). The attribute list holds only the non-id columns.
407412

408413
**Consider the flat alternative first.** An association costs a second query at
409414
runtime — the view returns the foreign key, and the client then fetches the

‎CHANGELOG.md‎

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

2727
- **`boundary event timer` without `interrupting` or `non interrupting` built at 0 errors and the app would not start** — it writes `Workflows$TimerBoundaryEvent`, a type no Mendix 11 runtime has (`Class 'Workflows$TimerBoundaryEvent' could not be found`, measured on 11.14.0; `mx check` and mxbuild both accept it). It was the form used in `mxcli syntax workflow boundary-event`. `mxcli check --references` and `exec` now refuse it on an 11.x project (**MDL-WF07**), in `CREATE WORKFLOW` and in every `ALTER WORKFLOW` op that can carry a boundary event; 10.x is left alone rather than guessed at. The syntax help and `write-workflows` skill name the kind, and say the delay is a DateTime expression (`'addDays([%CurrentDateTime%], 3)'`, not `'P3D'`).
2828

29+
- **Declaring a view entity's association column as an attribute wrote a model that does not build** (ako/view-entity-examples FINDINGS §4). `select m.ID as MeterRef` already gives a view entity an association named `MeterRef`, and writing it into the attribute list as well — `MeterRef: Trends.Meter` or `MeterRef: Trends.Meter.ID` — parsed, because a bare qualified name is how MDL spells an enumeration type. `exec` stored exactly that beside the association. Measured on 11.14.0: the two-part form fails the build with `CE1613 "The selected enumeration 'Trends.Meter' no longer exists"`, and the three-part form makes `mx check` throw `An error occurred when trying to set the 'Enumeration' property` before it validates anything. `mxcli check` passed it, and `check -p` could not say what was wrong: the id column is not an attribute, so it reported "1 columns but 2 attributes declared" and compared `MeterRef` against the next column's type.
30+
31+
`check` now refuses it with **no project** (MDL080): a declared name that is also an association column's alias, or a three-part type name, which no enumeration has. An entity-typed attribute under any other name needs the project to tell an entity from an enumeration, so `check -p` refuses that one, before the type comparison that would misreport it. `exec` refuses both **before writing anything**, `--no-check` included — measured, 0 files changed where it used to write the broken attribute. The reported recovery (a failed rollback leaving a stray `.mxunit`) is no longer reachable from this statement. The `write-oql-queries` skill says not to declare the id column.
32+
2933
- **A narrated demo's caption plate and highlight ring were placed in the wrong coordinate space whenever the take used `zoom`** — `record-narrated-demo`'s `take.js` reaches a fixed-width Mendix layout with CSS `zoom` on `html`, and `narrate.js` was written as though that did not exist. Under `html{zoom:z}` Chromium reports `getBoundingClientRect()` in **zoom-adjusted (video) pixels** but `getComputedStyle()` and `style.*` in **CSS pixels**, and the overlay got it wrong in both directions at once: `point()` read a rect and assigned it straight to `style.left`, so the highlight landed at *position × zoom* — measured at 1.6842, a target at (168, 202) ringed at (274, 330), which is a ring around the wrong control or off the frame entirely — while the caption plate, declared 96 CSS px tall, reached the file at 162 video px against a 184 px caption band.
3034

3135
Every overlay dimension is now stated in **video** pixels and divided by a zoom passed to `narrate.configure({ zoom })` — the same one handed to `openTake`. The reason this needed more than an arithmetic fix is that nothing reports it: the beat assertions pass, the contact sheet looks plausible, and the ring is simply around the wrong thing. So `checkOverlay()` measures the installed plate against the band and **throws** at record time rather than at edit time; its control is one line — build the overlay without telling it the zoom and it reports a 310 px plate starting at y770.

‎cmd/mxcli/lsp_diagnostics.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func (s *mdlServer) runSemanticValidation(text string) []protocol.Diagnostic {
301301
if viewStmt.Query.RawQuery != "" {
302302
violations = append(violations, executor.ValidateOQLSyntax(viewStmt.Query.RawQuery)...)
303303
violations = append(violations, executor.ValidateOQLTypes(viewStmt.Query.RawQuery, viewStmt.Attributes)...)
304+
violations = append(violations, executor.ValidateViewAttributeDeclarations(viewStmt.Query.RawQuery, viewStmt.Attributes)...)
304305
}
305306
}
306307
if s.widgetRegistry != nil {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- Bug: declaring a view entity's association column as an attribute wrote a
2+
-- model that does not build (ako/view-entity-examples FINDINGS §4).
3+
--
4+
-- `select m.ID as MeterRef` already gives the view entity an association named
5+
-- MeterRef (see view-entity-association.mdl). Declaring it again in the
6+
-- attribute list — `MeterRef: Trends.Meter`, or `MeterRef: Trends.Meter.ID` —
7+
-- parsed, because a bare qualified name is how MDL spells an enumeration type,
8+
-- and exec stored exactly that beside the association.
9+
--
10+
-- Measured on 11.14.0 before the fix, against a module with Trends.Meter,
11+
-- Trends.Reading and Trends.Reading_Meter:
12+
-- check -> "Check passed!"
13+
-- check -p -> "OQL select has 1 columns but 2 attributes declared", and
14+
-- MeterRef compared against the NEXT column ('r.Kwh')
15+
-- exec --no-check -> writes MeterRef: Enumeration(Trends.Meter)
16+
-- mx check -> CE1613 "The selected enumeration 'Trends.Meter' no longer exists."
17+
-- With Trends.Meter.ID: mx check throws "An error occurred when
18+
-- trying to set the 'Enumeration' property of a Enumeration"
19+
-- and validates nothing.
20+
--
21+
-- Fixed: MDL080 refuses it in check with no project, and exec refuses it before
22+
-- writing, --no-check included (0 files changed). An entity-typed attribute under
23+
-- a name that is NOT an association column needs the project to tell an entity
24+
-- from an enumeration; that refusal is in check -p and exec, and covered by unit
25+
-- tests in mdl/executor/view_attribute_object_test.go.
26+
--
27+
-- Expected: check fails with MDL080.
28+
29+
create view entity Trends.ReadingVE (
30+
MeterRef: Trends.Meter,
31+
Kwh: Decimal
32+
) as (
33+
from Trends.Reading as r
34+
join r/Trends.Reading_Meter/Trends.Meter as m
35+
select m.ID as MeterRef, r.Kwh as Kwh
36+
);

‎mdl/executor/cmd_entities.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,20 @@ func execCreateViewEntity(ctx *ExecContext, s *ast.CreateViewEntityStmt) error {
730730
}
731731
}
732732

733+
// An attribute that tries to hold an object is refused here as well as by
734+
// check, because `exec --no-check` otherwise writes it — as an enumeration
735+
// type naming an entity, which fails the build or stops mx check from
736+
// loading the project (FINDINGS §4).
737+
var objErrors []string
738+
for _, v := range ValidateViewAttributeDeclarations(s.Query.RawQuery, s.Attributes) {
739+
objErrors = append(objErrors, v.Message+". "+v.Suggestion)
740+
}
741+
objErrors = append(objErrors, viewAttributeEntityTypeErrors(ctx, s.Query.RawQuery, s.Attributes, nil)...)
742+
if len(objErrors) > 0 {
743+
return mdlerrors.NewValidationf("view entity '%s':\n - %s",
744+
s.Name.String(), strings.Join(objErrors, "\n - "))
745+
}
746+
733747
// Find module
734748
module, err := findModule(ctx, s.Name.Module)
735749
if err != nil {

‎mdl/executor/oql_view_associations.go‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"regexp"
88
"strings"
99

10+
"github.com/mendixlabs/mxcli/mdl/ast"
1011
mdlerrors "github.com/mendixlabs/mxcli/mdl/errors"
12+
"github.com/mendixlabs/mxcli/mdl/linter"
1113
"github.com/mendixlabs/mxcli/model"
1214
"github.com/mendixlabs/mxcli/sdk/domainmodel"
1315
)
@@ -420,3 +422,111 @@ func validateViewAssociationNames(ctx *ExecContext, moduleName, viewEntityName,
420422
}
421423
return out
422424
}
425+
426+
// viewAttributeIsObjectRule refuses a view entity attribute that tries to hold
427+
// an object: one declared for an association column, or typed with an entity.
428+
const viewAttributeIsObjectRule = "MDL080"
429+
430+
// ValidateViewAttributeDeclarations reports declared attributes that cannot be
431+
// attributes (ako/view-entity-examples FINDINGS §4), from the script alone.
432+
//
433+
// Writing the association column as a declared attribute — `MeterRef:
434+
// Trends.Meter` or `MeterRef: Trends.Meter.ID` beside `select m.ID as MeterRef`
435+
// — parses, because a bare qualified name is how MDL spells an enumeration
436+
// type. It was stored as exactly that, next to the association the column
437+
// already declares. Measured on 11.14.0: the two-part form is CE1613 "The
438+
// selected enumeration 'Trends.Meter' no longer exists"; the three-part form
439+
// makes mx check throw "An error occurred when trying to set the 'Enumeration'
440+
// property" before it validates anything. And `check -p` could not say so: the
441+
// column is not an attribute, so it reported "1 columns but 2 attributes" and
442+
// compared the declaration against the NEXT column's type.
443+
//
444+
// Two shapes are decidable without a project: a declared name that is also an
445+
// association column's alias, and a three-part type name, which no enumeration
446+
// has. An entity-typed attribute under any other name needs the project to tell
447+
// an entity from an enumeration — see viewAttributeEntityTypeErrors.
448+
func ValidateViewAttributeDeclarations(oql string, attrs []ast.ViewAttribute) []linter.Violation {
449+
assocByName := map[string]viewAssociationColumn{}
450+
for _, c := range viewAssociationColumns(oql) {
451+
assocByName[strings.ToLower(c.Name)] = c
452+
}
453+
var out []linter.Violation
454+
for _, a := range attrs {
455+
if c, ok := assocByName[strings.ToLower(a.Name)]; ok {
456+
out = append(out, viewAttributeViolation(fmt.Sprintf(
457+
"attribute '%s' cannot be declared: the select column '%s as %s' already makes %s an "+
458+
"association to %s, and an association is not an attribute",
459+
a.Name, c.Expr, c.Name, c.Name, c.Entity),
460+
fmt.Sprintf("Remove '%s' from the attribute list — the column is the whole declaration", a.Name)))
461+
continue
462+
}
463+
if ref := enumRefOf(a.Type); ref != nil && strings.Contains(ref.Name, ".") {
464+
out = append(out, viewAttributeViolation(fmt.Sprintf(
465+
"attribute '%s': '%s' is not a type — an attribute cannot hold an object or its id",
466+
a.Name, ref.String()),
467+
objectAttributeAdvice(a.Name)))
468+
}
469+
}
470+
return out
471+
}
472+
473+
// viewAttributeEntityTypeErrors reports attributes typed with a name that is an
474+
// entity rather than an enumeration. It needs the project (or the script's own
475+
// entities) to tell the two apart, which the parser cannot.
476+
func viewAttributeEntityTypeErrors(ctx *ExecContext, oql string, attrs []ast.ViewAttribute, scriptEntities map[string]bool) []string {
477+
if ctx == nil || !ctx.Connected() {
478+
return nil
479+
}
480+
// An association column's name is already refused by MDL080, whatever its
481+
// type; reporting it twice would read as two problems.
482+
associationNames := map[string]bool{}
483+
for _, c := range viewAssociationColumns(oql) {
484+
associationNames[strings.ToLower(c.Name)] = true
485+
}
486+
var entities map[string]bool
487+
var out []string
488+
for _, a := range attrs {
489+
ref := enumRefOf(a.Type)
490+
if ref == nil || ref.Module == "" || strings.Contains(ref.Name, ".") || associationNames[strings.ToLower(a.Name)] {
491+
continue
492+
}
493+
qn := ref.String()
494+
if entities == nil {
495+
entities = buildEntityQualifiedNames(ctx)
496+
}
497+
if !scriptEntities[qn] && !entities[qn] {
498+
continue
499+
}
500+
if enumerationExists(ctx, qn) {
501+
continue
502+
}
503+
out = append(out, fmt.Sprintf(
504+
"attribute '%s': %s is an entity, not an enumeration — an attribute cannot hold an object "+
505+
"(it would be stored as Enumeration(%s), which fails the build with CE1613). %s",
506+
a.Name, qn, qn, objectAttributeAdvice(a.Name)))
507+
}
508+
return out
509+
}
510+
511+
func enumRefOf(dt ast.DataType) *ast.QualifiedName {
512+
if dt.Kind != ast.TypeEnumeration {
513+
return nil
514+
}
515+
return dt.EnumRef
516+
}
517+
518+
func objectAttributeAdvice(name string) string {
519+
return fmt.Sprintf("For an association, select the entity's id under this name and do not declare it: "+
520+
"`select m.ID as %s` (m being the entity's alias in the FROM/JOIN). For the id as text, "+
521+
"declare '%s: String' and select `cast(m.ID as string) as %s`", name, name, name)
522+
}
523+
524+
func viewAttributeViolation(msg, suggestion string) linter.Violation {
525+
return linter.Violation{
526+
RuleID: viewAttributeIsObjectRule,
527+
Severity: linter.SeverityError,
528+
Message: msg,
529+
Location: linter.Location{DocumentType: "viewentity"},
530+
Suggestion: suggestion,
531+
}
532+
}

0 commit comments

Comments
 (0)