Skip to content

Commit 21fb8df

Browse files
authored
Ignore subgraph input validation (#1374)
## Description Added an option to skip input value validation for non-root subgraphs in the component spec validation process. This change allows subgraphs to have required inputs without values, which is valid when they're not at the root level of a pipeline. ## Type of Change - [x] Bug fix - [x] Improvement ## Checklist - [x] I have tested this does not break current pipelines / runs functionality - [x] I have tested the changes on staging ## Test Instructions 1. Create a pipeline with nested subgraphs 2. Add required inputs to a non-root subgraph without providing values 3. Verify that validation errors are not shown for these inputs 4. Verify that root-level subgraphs still properly validate required inputs
1 parent b531d53 commit 21fb8df

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

src/providers/ComponentSpecProvider.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@ export const ComponentSpecProvider = ({
8787
return getSubgraphComponentSpec(componentSpec, currentSubgraphPath);
8888
}, [componentSpec, currentSubgraphPath]);
8989

90+
const isRootSubgraph = currentSubgraphPath.length === 1;
91+
9092
const { isValid, errors } = useMemo(
91-
() => checkComponentSpecValidity(currentSubgraphSpec),
92-
[currentSubgraphSpec],
93+
() =>
94+
checkComponentSpecValidity(currentSubgraphSpec, {
95+
skipInputValueValidation: !isRootSubgraph,
96+
}),
97+
[currentSubgraphSpec, isRootSubgraph],
9398
);
9499

95100
const clearComponentSpec = useCallback(() => {

src/utils/validations.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ describe("checkComponentSpecValidity", () => {
106106
);
107107
});
108108

109+
it("should skip required input value validation when option enabled", () => {
110+
const componentSpec: ComponentSpec = {
111+
name: "test-component",
112+
implementation: { container: { image: "test-image" } },
113+
inputs: [{ name: "no-value", type: "string", optional: false }],
114+
};
115+
116+
const result = checkComponentSpecValidity(componentSpec, {
117+
skipInputValueValidation: true,
118+
});
119+
120+
expect(result.isValid).toBe(true);
121+
expect(result.errors).not.toContain(
122+
'Pipeline input "no-value" is required and does not have a value',
123+
);
124+
});
125+
109126
it("should return error for output without name", () => {
110127
const componentSpec: ComponentSpec = {
111128
name: "test-component",

src/utils/validations.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import {
99
type TaskSpec,
1010
} from "./componentSpec";
1111

12+
interface ValidationOptions {
13+
skipInputValueValidation?: boolean;
14+
}
15+
1216
export const checkComponentSpecValidity = (
1317
componentSpec: ComponentSpec,
18+
options?: ValidationOptions,
1419
): { isValid: boolean; errors: string[] } => {
1520
const errors: string[] = [];
21+
const { skipInputValueValidation = false } = options ?? {};
1622

1723
// Basic validation
1824
const basicErrors = validateBasicComponentSpec(componentSpec);
@@ -26,7 +32,9 @@ export const checkComponentSpecValidity = (
2632
}
2733

2834
// Validate inputs and outputs
29-
errors.push(...validateInputsAndOutputs(componentSpec));
35+
errors.push(
36+
...validateInputsAndOutputs(componentSpec, skipInputValueValidation),
37+
);
3038

3139
// Skip further validation for non-graph implementations
3240
if (!isGraphImplementation(componentSpec.implementation)) {
@@ -68,7 +76,10 @@ const validateBasicComponentSpec = (componentSpec: ComponentSpec): string[] => {
6876
return errors;
6977
};
7078

71-
const validateInputsAndOutputs = (componentSpec: ComponentSpec): string[] => {
79+
const validateInputsAndOutputs = (
80+
componentSpec: ComponentSpec,
81+
skipInputValueValidation: boolean,
82+
): string[] => {
7283
const errors: string[] = [];
7384

7485
// Validate inputs array structure
@@ -87,7 +98,12 @@ const validateInputsAndOutputs = (componentSpec: ComponentSpec): string[] => {
8798
}
8899

89100
// Check that required inputs have a value or default
90-
if (!input.optional && !input.default && !input.value) {
101+
if (
102+
!skipInputValueValidation &&
103+
!input.optional &&
104+
!input.default &&
105+
!input.value
106+
) {
91107
errors.push(
92108
`Pipeline input "${input.name}" is required and does not have a value`,
93109
);

0 commit comments

Comments
 (0)