fix: non-processible error when empty body is sent to fastAPI#10248
Conversation
WalkthroughRefactors a frontend API query to type the POST request body using Node and Edge from @xyflow/react and constructs a requestBody object from flow nodes/edges, replacing prior data payload usage. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning, 2 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const data = { | ||
| data: {}, | ||
| }; | ||
| let requestBody: { nodes: any[]; edges: any[] } | null = null; |
There was a problem hiding this comment.
nit
diff --git a/src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx b/src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
index a0c80412ca..8b893d7d9d 100644
--- a/src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
+++ b/src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
@@ -1,4 +1,4 @@
-import type { ReactFlowJsonObject } from "@xyflow/react";
+import type { Edge, Node, ReactFlowJsonObject } from "@xyflow/react";
import type { AxiosRequestConfig } from "axios";
import type { useMutationFunctionType } from "@/types/api";
import { api } from "../../api";
@@ -42,7 +42,7 @@ export const usePostRetrieveVertexOrder: useMutationFunctionType<
start_component_id: decodeURIComponent(startNodeId),
};
}
- let requestBody: { nodes: any[]; edges: any[] } | null = null;
+ let requestBody: { nodes: Node[]; edges: Edge[] } | null = null;
if (flow && flow.nodes && flow.edges) {
const { nodes, edges } = flow;
requestBody = {
| flow_id: uuid.UUID, | ||
| background_tasks: BackgroundTasks, | ||
| data: Annotated[FlowDataRequest | None, Body(embed=True)] | None = None, | ||
| data: FlowDataRequest | None = None, |
There was a problem hiding this comment.
This is not needed for the fix.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (1)
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/frontend/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/frontend_development.mdc)
src/frontend/src/**/*.{ts,tsx,js,jsx}: All frontend TypeScript and JavaScript code should be located under src/frontend/src/ and organized into components, pages, icons, stores, types, utils, hooks, services, and assets directories as per the specified directory layout.
Use React 18 with TypeScript for all UI components in the frontend.
Format all TypeScript and JavaScript code using the make format_frontend command.
Lint all TypeScript and JavaScript code using the make lint command.
Files:
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
🧠 Learnings (3)
📚 Learning: 2025-06-23T12:46:42.048Z
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: React Flow should be used for flow graph visualization, with nodes and edges passed as props, and changes handled via onNodesChange and onEdgesChange callbacks.
Applied to files:
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
📚 Learning: 2025-07-18T18:27:12.609Z
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-07-18T18:27:12.609Z
Learning: Applies to src/frontend/src/components/**/@(FlowGraph|nodes)/**/*.{ts,tsx,js,jsx} : Use React Flow for flow graph visualization components.
Applied to files:
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
📚 Learning: 2025-06-23T12:46:42.048Z
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Custom React Flow node types should be implemented as memoized components, using Handle components for connection points and supporting optional icons and labels.
Applied to files:
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
🧬 Code graph analysis (1)
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx (1)
src/frontend/src/controllers/API/helpers/constants.ts (1)
getURL(37-47)
🔇 Additional comments (2)
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx (2)
1-1: LGTM! Proper type imports added.Adding
NodeandEdgetype imports improves type safety for the request body structure.
53-57: API call structure is correct.The POST request properly uses the typed
requestBody. Once thenullbody issue is addressed, this will correctly send the flow structure to the backend.
| let requestBody: { nodes: Node[]; edges: Edge[] } | null = null; | ||
| if (flow && flow.nodes && flow.edges) { | ||
| const { nodes, edges } = flow; | ||
| data["data"]["nodes"] = nodes; | ||
| data["data"]["edges"] = edges; | ||
| requestBody = { | ||
| nodes, | ||
| edges, | ||
| }; | ||
| } |
There was a problem hiding this comment.
Sending null body likely causes the 422 error.
When flow is missing or lacks nodes/edges, requestBody stays null. FastAPI/Pydantic endpoints typically reject null bodies with 422 validation errors because they expect an object matching the schema.
Apply this diff to always send a valid object structure:
- let requestBody: { nodes: Node[]; edges: Edge[] } | null = null;
- if (flow && flow.nodes && flow.edges) {
- const { nodes, edges } = flow;
- requestBody = {
- nodes,
- edges,
- };
- }
+ const requestBody: { nodes: Node[]; edges: Edge[] } = {
+ nodes: flow?.nodes ?? [],
+ edges: flow?.edges ?? [],
+ };This ensures the backend always receives { nodes: [], edges: [] } rather than null, which should resolve the 422 error mentioned in the PR description.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let requestBody: { nodes: Node[]; edges: Edge[] } | null = null; | |
| if (flow && flow.nodes && flow.edges) { | |
| const { nodes, edges } = flow; | |
| data["data"]["nodes"] = nodes; | |
| data["data"]["edges"] = edges; | |
| requestBody = { | |
| nodes, | |
| edges, | |
| }; | |
| } | |
| const requestBody: { nodes: Node[]; edges: Edge[] } = { | |
| nodes: flow?.nodes ?? [], | |
| edges: flow?.edges ?? [], | |
| }; |
🤖 Prompt for AI Agents
In
src/frontend/src/controllers/API/queries/vertex/use-post-retrieve-vertex-order.tsx
around lines 45 to 52, requestBody can remain null when flow or its nodes/edges
are missing which causes a 422 from the FastAPI endpoint; change the logic to
always build a valid object by defaulting to { nodes: [], edges: [] } when flow
is absent or missing properties (e.g., set requestBody = { nodes: flow?.nodes ??
[], edges: flow?.edges ?? [] } or equivalent) so the backend always receives a
proper object instead of null.
* Fix non-processible erro when empty body is sent to fastAPI * Annotate FlowDataRequest with Body for embedding * Refine requestBody type for vertex order retrieval * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
#10253) * Fix non-processible erro when empty body is sent to fastAPI * Annotate FlowDataRequest with Body for embedding * Refine requestBody type for vertex order retrieval * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…ow-ai#10248) * Fix non-processible erro when empty body is sent to fastAPI * Annotate FlowDataRequest with Body for embedding * Refine requestBody type for vertex order retrieval * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…ow-ai#10248) * Fix non-processible erro when empty body is sent to fastAPI * Annotate FlowDataRequest with Body for embedding * Refine requestBody type for vertex order retrieval * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…ow-ai#10248) * Fix non-processible erro when empty body is sent to fastAPI * Annotate FlowDataRequest with Body for embedding * Refine requestBody type for vertex order retrieval * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…ow-ai#10248) * Fix non-processible erro when empty body is sent to fastAPI * Annotate FlowDataRequest with Body for embedding * Refine requestBody type for vertex order retrieval * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…ow-ai#10248) * Fix non-processible erro when empty body is sent to fastAPI * Annotate FlowDataRequest with Body for embedding * Refine requestBody type for vertex order retrieval * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>



Fixes a 422 received after upgrading pydantic/fastAPI dependencies.
To repro:
I don't know the exact reason this is required nor if it is the best fix, hence draft.
Summary by CodeRabbit
Refactor
Chores
No functional changes are expected for end-users; these updates enhance stability and prepare the codebase for future improvements.