Skip to content

Commit 2f1a01c

Browse files
Matovidloclaude
andcommitted
fix(model): tighten Config.ParentKey fallback to variables configs only
- Require both ErrMultipleParents AND ComponentID == keboola.VariablesComponentID before falling back to branch parent, so schedulers and other component types with unexpected multi-parent errors are never silently swallowed - Remove inaccurate claim that VariablesForRelation is only constructed by NewOtherSideRelation; the comment now simply states the invariant - Add TestConfig_ParentKey_MultipleParentsFallsBackToBranch to cover the shared-variables fallback path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 14986e9 commit 2f1a01c

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

internal/pkg/model/object.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,19 +595,17 @@ func (r *ConfigRow) GetContent() *orderedmap.OrderedMap {
595595
}
596596

597597
// ParentKey - config parent can be modified via Relations, e.g. variables config embedded in another config.
598-
// When Relations.ParentKey returns ErrMultipleParents (a shared variables config), fall back to the
599-
// structural parent (branch). VariablesForRelation is only ever constructed by
600-
// VariablesFromRelation.NewOtherSideRelation, which hard-codes ComponentID: keboola.VariablesComponentID,
601-
// so neither checkDefinedOn guard can trigger in practice. All other errors are propagated.
598+
// When a keboola.variables config is shared by multiple consumers (ErrMultipleParents), fall back to the
599+
// structural parent (branch). All other errors are propagated.
602600
func (c *Config) ParentKey() (Key, error) {
603601
parentKey, err := c.Relations.ParentKey(c.Key())
604602
if err == nil && parentKey != nil {
605603
return parentKey, nil
606604
}
607-
if err != nil && !errors.Is(err, ErrMultipleParents) {
605+
if err != nil && (!errors.Is(err, ErrMultipleParents) || c.ComponentID != keboola.VariablesComponentID) {
608606
return nil, err
609607
}
610-
// No relation-defined parent, or multiple parents (shared variables config)
608+
// No relation-defined parent, or shared variables config with multiple consumers
611609
// fall back to the structural parent (branch).
612610
return c.ConfigKey.ParentKey()
613611
}

internal/pkg/model/object_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/keboola/go-utils/pkg/wildcards"
8+
"github.com/keboola/keboola-sdk-go/v2/pkg/keboola"
89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
1011

@@ -94,6 +95,20 @@ func TestBranchMetadata_UpsertTemplateInstance_New(t *testing.T) {
9495
}, usages)
9596
}
9697

98+
func TestConfig_ParentKey_MultipleParentsFallsBackToBranch(t *testing.T) {
99+
t.Parallel()
100+
cfg := &Config{
101+
ConfigKey: ConfigKey{BranchID: 1, ComponentID: keboola.VariablesComponentID, ID: "3"},
102+
Relations: Relations{
103+
&VariablesForRelation{ComponentID: "ex-generic-v2", ConfigID: "1"},
104+
&VariablesForRelation{ComponentID: "ex-generic-v2", ConfigID: "2"},
105+
},
106+
}
107+
parentKey, err := cfg.ParentKey()
108+
require.NoError(t, err)
109+
assert.Equal(t, BranchKey{ID: 1}, parentKey)
110+
}
111+
97112
func TestBranchMetadata_DeleteTemplateUsage(t *testing.T) {
98113
t.Parallel()
99114

0 commit comments

Comments
 (0)