-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Summary
When mxcli exec generates microflows with CREATE/CHANGE OBJECT activities, two related bugs cause invalid BSON that produces CE1613 errors in Studio Pro (and can crash Studio Pro during version control status refresh with System.InvalidOperationException: Sequence contains no matching element).
Bug 1: Association stored in Attribute field (ChangeActionItem)
Location: mdl/executor/cmd_microflows_builder_actions.go:106 (and line 262)
The executor uses strings.Contains(change.Attribute, ".") to distinguish associations from attributes:
if strings.Contains(change.Attribute, ".") {
memberChange.AssociationQualifiedName = change.Attribute
} else if entityQN != "" {
memberChange.AttributeQualifiedName = entityQN + "." + change.Attribute
}This heuristic fails because association names in MDL don't contain dots (e.g. Child_Parent), so they are misclassified as attributes.
Result: The BSON ChangeActionItem writes the association name into the Attribute field instead of the Association field:
// WRONG (current)
{ "Association": "", "Attribute": "Demo.Child.Child_Parent" }
// CORRECT
{ "Association": "Demo.Child_Parent", "Attribute": "" }Studio Pro error:
[CE1613] "The selected attribute 'Demo.Child.Child_Parent' no longer exists."
Bug 2: Entity type treated as Enumeration in DECLARE
Location: mdl/visitor/visitor_helpers.go:365
buildDataType() defaults bare qualified names (e.g. Demo.Parent) to TypeEnumeration:
// Handle bare qualified name (entity reference or enumeration)
if qn := dtCtx.QualifiedName(); qn != nil {
return ast.DataType{Kind: ast.TypeEnumeration, EnumRef: &name} // ← always enum!
}When a DECLARE statement uses an entity type (DECLARE $Item Demo.Parent = empty), the visitor cannot distinguish it from an enumeration type and defaults to enum.
Result: The BSON CreateVariableAction.VariableType uses DataTypes$EnumerationType instead of DataTypes$ObjectType:
// WRONG (current)
{ "$Type": "DataTypes$EnumerationType", "Enumeration": "Demo.Parent" }
// CORRECT
{ "$Type": "DataTypes$ObjectType", "Entity": "Demo.Parent" }Studio Pro error:
[CE1613] "The selected enumeration 'Demo.Parent' no longer exists."
Root Cause
Both bugs share the same root cause: the visitor and executor lack access to the domain model catalog, so they cannot determine whether a qualified name refers to an entity, enumeration, or association. They rely on fragile heuristics (presence of . in name, or defaulting to one type) instead of querying the catalog.
Minimal Reproduction
CREATE PERSISTENT ENTITY Demo.Parent (
Name: String(100)
);
CREATE PERSISTENT ENTITY Demo.Child (
Label: String(100)
);
CREATE ASSOCIATION Demo.Child_Parent
FROM Demo.Child TO Demo.Parent;
-- Bug 1: Association in CREATE OBJECT
CREATE MICROFLOW Demo.Bug1 ()
BEGIN
$Parent = CREATE Demo.Parent (Name = 'test');
$Child = CREATE Demo.Child (
Label = 'test',
Child_Parent = $Parent);
END;
/
-- Bug 2: Entity type in DECLARE
CREATE MICROFLOW Demo.Bug2 ()
BEGIN
DECLARE $Item Demo.Parent = empty;
END;
/Run with: mxcli exec repro.mdl -p app.mpr, then mx check app.mpr to see CE1613 errors.
Suggested Fix
The executor should query the catalog (or domain model) to resolve names:
-
Bug 1: Before building
ChangeActionItem, look up the member name against the entity's attributes and associations. If found in associations, setAssociationQualifiedName; otherwise setAttributeQualifiedName. -
Bug 2: In
buildDataType(), when encountering a bare qualified name, the resolver should check the catalog to determine if it's an entity or enumeration and return the correctDataType.Kind. As a fallback (when no catalog is available, e.g.mxcli checkwithout-p), the current default-to-enum behavior could remain, but a warning should be emitted.