Skip to content

Commit 8d8017f

Browse files
committed
fix: reorder auto-datasource before child slots + validate Caption presence
- Move auto-datasource resolution (step 4) before applyChildSlots (step 4.1) so entityContext is available for child widgets that depend on it. - Return validation error from setWidgetCaption when widget has no Caption property, matching setWidgetContent behavior (instead of silently injecting a plain string field).
1 parent d022df3 commit 8d8017f

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

mdl/executor/bson_helpers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ func setRawWidgetProperty(widget bson.D, propName string, value interface{}) err
356356
func setWidgetCaption(widget bson.D, value interface{}) error {
357357
caption := dGetDoc(widget, "Caption")
358358
if caption == nil {
359-
setTranslatableText(widget, "Caption", value)
360-
return nil
359+
return mdlerrors.NewValidation("widget has no Caption property")
361360
}
362361
setTranslatableText(caption, "", value)
363362
return nil

mdl/executor/widget_engine.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ func (e *PluggableWidgetEngine) Build(def *WidgetDefinition, w *ast.WidgetV3) (*
129129
}
130130
}
131131

132-
// 4. Apply child slots (.def.json)
133-
if err := e.applyChildSlots(builder, slots, w, propertyTypeIDs); err != nil {
134-
return nil, err
135-
}
136-
137-
// 4.1 Auto datasource: map AST DataSource to first DataSource-type property.
132+
// 4. Auto datasource: map AST DataSource to first DataSource-type property.
133+
// This must run before child slots so that entityContext is available
134+
// for child widgets that depend on the parent's data source.
138135
dsHandledByMapping := false
139136
for _, m := range mappings {
140137
if m.Source == "DataSource" {
@@ -160,6 +157,11 @@ func (e *PluggableWidgetEngine) Build(def *WidgetDefinition, w *ast.WidgetV3) (*
160157
}
161158
}
162159

160+
// 4.1 Apply child slots (.def.json)
161+
if err := e.applyChildSlots(builder, slots, w, propertyTypeIDs); err != nil {
162+
return nil, err
163+
}
164+
163165
// 4.3 Auto child slots: match AST children to Widgets-type template properties.
164166
handledSlotKeys := make(map[string]bool)
165167
for _, s := range slots {

0 commit comments

Comments
 (0)