Skip to content

Commit caeccbd

Browse files
Matovidloclaude
andcommitted
fix(model): simplify Config.ParentKey condition; add propagation test
- Restructure the ErrMultipleParents guard from a double-negative into a positive if/else — same semantics, more readable at a glance - Add TestConfig_ParentKey_MultipleParentsPropagatesForNonVariables: uses two SchedulerForRelation entries (whose checkDefinedOn has no component-ID guard) to verify that ErrMultipleParents is propagated for non-variables component types, preventing future refactors from accidentally widening the fallback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2f1a01c commit caeccbd

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

internal/pkg/model/object.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,14 @@ func (c *Config) ParentKey() (Key, error) {
602602
if err == nil && parentKey != nil {
603603
return parentKey, nil
604604
}
605-
if err != nil && (!errors.Is(err, ErrMultipleParents) || c.ComponentID != keboola.VariablesComponentID) {
605+
if err != nil {
606+
if errors.Is(err, ErrMultipleParents) && c.ComponentID == keboola.VariablesComponentID {
607+
// Shared variables config with multiple consumers — fall back to structural parent.
608+
return c.ConfigKey.ParentKey()
609+
}
606610
return nil, err
607611
}
608-
// No relation-defined parent, or shared variables config with multiple consumers —
609-
// fall back to the structural parent (branch).
612+
// No relation-defined parent — fall back to the structural parent (branch).
610613
return c.ConfigKey.ParentKey()
611614
}
612615

internal/pkg/model/object_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ func TestConfig_ParentKey_MultipleParentsFallsBackToBranch(t *testing.T) {
109109
assert.Equal(t, BranchKey{ID: 1}, parentKey)
110110
}
111111

112+
func TestConfig_ParentKey_MultipleParentsPropagatesForNonVariables(t *testing.T) {
113+
t.Parallel()
114+
// SchedulerForRelation.checkDefinedOn only requires a ConfigKey (no component-ID check),
115+
// so two entries on the same config reach the multi-parents sentinel without being
116+
// rejected by a component guard first.
117+
cfg := &Config{
118+
ConfigKey: ConfigKey{BranchID: 1, ComponentID: keboola.SchedulerComponentID, ID: "3"},
119+
Relations: Relations{
120+
&SchedulerForRelation{ComponentID: "ex-generic-v2", ConfigID: "1"},
121+
&SchedulerForRelation{ComponentID: "ex-generic-v2", ConfigID: "2"},
122+
},
123+
}
124+
_, err := cfg.ParentKey()
125+
require.Error(t, err)
126+
assert.ErrorIs(t, err, ErrMultipleParents)
127+
}
128+
112129
func TestBranchMetadata_DeleteTemplateUsage(t *testing.T) {
113130
t.Parallel()
114131

0 commit comments

Comments
 (0)