File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,20 @@ async def write_resource(
151151 try :
152152 # Get content from request body
153153
154+ # Defensive type checking: ensure content is a string
155+ # FastAPI should validate this, but if a dict somehow gets through
156+ # (e.g., via JSON body parsing), we need to catch it here
157+ if isinstance (content , dict ):
158+ logger .error (
159+ f"Error writing resource { file_path } : "
160+ f"content is a dict, expected string. Keys: { list (content .keys ())} "
161+ )
162+ raise HTTPException (
163+ status_code = 400 ,
164+ detail = "content must be a string, not a dict. "
165+ "Ensure request body is sent as raw string content, not JSON object." ,
166+ )
167+
154168 # Ensure it's UTF-8 string content
155169 if isinstance (content , bytes ): # pragma: no cover
156170 content_str = content .decode ("utf-8" )
Original file line number Diff line number Diff line change @@ -110,7 +110,14 @@ async def canvas(
110110
111111 # Write the file using the resource API
112112 logger .info (f"Creating canvas file: { file_path } in project { project } " )
113- response = await call_put (client , f"{ project_url } /resource/{ file_path } " , json = canvas_json )
113+ # Send canvas_json as content string, not as json parameter
114+ # The resource endpoint expects Body() string content, not JSON-encoded data
115+ response = await call_put (
116+ client ,
117+ f"{ project_url } /resource/{ file_path } " ,
118+ content = canvas_json ,
119+ headers = {"Content-Type" : "text/plain" },
120+ )
114121
115122 # Parse response
116123 result = response .json ()
You can’t perform that action at this time.
0 commit comments