Skip to content

fix(writer): ComboBox BSON serialization causes CE1613 — enum written as association, missing EntityRef #33

@engalar

Description

@engalar

Summary

buildComboBoxV3() produces incorrect BSON for both enumeration-mode and association-mode combo boxes, causing CE1613 errors ("The selected association/attribute no longer exists") when the page is opened in Studio Pro or validated with mx check.

Reproduction

Affected pages in GenAIDemo baseline (MyFirstModule):

Page Widget Error Count
P_ComboBox_Enum cmbPriority "association 'MyFirstModule.Priority' no longer exists" 1
P_ComboBox_Assoc cmbCategory "attribute of combo box 'cmbCategory'" 7

Root Cause

Bug 1: Enum mode — optionsSourceType not reset to "enumeration"

File: mdl/executor/cmd_pages_builder_v3_pluggable.go:91-99

In enum mode (no DataSource), the builder sets attributeEnumeration but never explicitly sets optionsSourceType. It relies on the template default ("enumeration"), which works for fresh templates. However, the BSON in the MPR shows optionsSourceType = "association", causing Mendix to interpret the enum attribute Priority as an association lookup.

Fix: Explicitly set optionsSourceType to "enumeration" in the else branch.

Bug 2: Association mode — EntityRef remains null

File: mdl/executor/cmd_pages_builder_input.go:179-201

For P_ComboBox_Assoc, the attributeAssociation property value shows:

AttributeRef.Attribute = "MyFirstModule.Task.Task_Category"
EntityRef = null

A correct association-mode combo box requires EntityRef = IndirectEntityRef with EntityRefStep containing the Association path and DestinationEntity. The setAssociationRef() function targets the EntityRef key but the resulting BSON still has EntityRef: null, suggesting the template structure or key matching isn't working as expected.

Additionally, the test MDL uses CaptionAttribute: Task_Category (an association name) instead of an attribute on the target entity (e.g., Name), which compounds the error.

Expected BSON (association mode)

attributeAssociation:
  EntityRef: IndirectEntityRef
    Steps:
      - EntityRefStep
          Association: "MyFirstModule.Task_Category"
          DestinationEntity: "MyFirstModule.Category"
  AttributeRef: null

References

  • Builder code: mdl/executor/cmd_pages_builder_v3_pluggable.go:31-122
  • Association ref setter: mdl/executor/cmd_pages_builder_input.go:179-201
  • Attribute ref setter: mdl/executor/cmd_pages_builder_input.go:206-225
  • Working roundtrip test: mdl/executor/roundtrip_mxcheck_test.go:742-847 (TestMxCheck_ComboBoxWithAssociation)
  • ComboBox template: sdk/widgets/templates/mendix-11.6/combobox.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions