{"record":{"id":"a4ba66dac7bd6140","repo":"appsmithorg/appsmith","slug":"updatemodel-expects-an-object-as-parameter-a4ba66","errorCode":null,"errorMessage":"updateModel expects an object as parameter","messagePattern":"updateModel expects an object as parameter","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/client/src/widgets/wds/WDSCustomWidget/component/customWidgetscript.js","lineNumber":239,"sourceCode":"          if (typeof fn !== \"function\") {\n            throw new Error(\"onModelChange expects a function as parameter\");\n          }\n\n          modelSubscribers.push(fn);\n          fn(window.appsmith.model);\n\n          return () => {\n            // Unsubscribe from model changes\n            const index = modelSubscribers.indexOf(fn);\n\n            if (index > -1) {\n              modelSubscribers.splice(index, 1);\n            }\n          };\n        },\n        updateModel: (obj) => {\n          if (!obj || typeof obj !== \"object\") {\n            throw new Error(\"updateModel expects an object as parameter\");\n          }\n\n          appsmith.model = Object.assign(\n            Object.assign({}, appsmith.model),\n            obj,\n          );\n\n          // Send an update model message to the parent\n          channel.postMessage(EVENTS.CUSTOM_WIDGET_UPDATE_MODEL, obj);\n        },\n        triggerEvent: (eventName, contextObj) => {\n          if (typeof eventName !== \"string\") {\n            throw new Error(\"eventName should be a string\");\n          } else if (contextObj && typeof contextObj !== \"object\") {\n            throw new Error(\"contextObj should be an object\");\n          }\n\n          // Send a trigger event message to the parent","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/appsmithorg/appsmith/blob/8cd9021c24cdbea1c3c12c966073708e83db60c2/app/client/src/widgets/wds/WDSCustomWidget/component/customWidgetscript.js#L221-L257","documentation":"Thrown by window.appsmith.updateModel() in the WDS Custom Widget iframe. Same contract as the legacy widget: merges a partial object into appsmith.model and posts a CUSTOM_WIDGET_UPDATE_MODEL delta to the parent. Rejects null/undefined and non-object primitives because the Object.assign merge and message serialization require a plain object.","triggerScenarios":"Calling appsmith.updateModel(null), appsmith.updateModel(undefined), appsmith.updateModel('foo'), appsmith.updateModel(42), or appsmith.updateModel() with no argument inside the WDS widget.","commonSituations":"Building a patch conditionally that collapses to undefined; forwarding a raw input string instead of an object; spreading a possibly-null variable without a default.","solutions":["Pass a plain object literal: appsmith.updateModel({ selectedId: id }).","Default optional patches: appsmith.updateModel(patch ?? {}).","Assemble the patch in a typed local first so it can never be a primitive.","Wrap arrays under a key: appsmith.updateModel({ rows: rowsArray })."],"exampleFix":"// before\nappsmith.updateModel(form.value); // form.value is a string\n\n// after\nappsmith.updateModel({ value: form.value });","handlingStrategy":"validation","validationCode":"const patch = maybePatch ?? {};\nif (typeof patch !== 'object' || patch === null) {\n  throw new TypeError('updateModel needs a plain object');\n}\nappsmith.updateModel(patch);","typeGuard":"const isPlainObject = (v) =>\n  v !== null && typeof v === 'object' && !Array.isArray(v);\n\n// usage\nif (isPlainObject(patch)) appsmith.updateModel(patch);","tryCatchPattern":"try {\n  appsmith.updateModel(patch ?? {});\n} catch (e) {\n  console.error('updateModel rejected patch:', e.message);\n}","preventionTips":["Always pass a plain object literal; wrap scalar values under a key.","Default optional patches with ?? {}.","Reject arrays at the call site to prevent silent mis-merges.","Type the patch as Record<string, unknown> for compile-time safety."],"tags":["custom-widget","wds","appsmith-api","parameter-validation","javascript"],"backgroundTag":null,"analyzedSha":"8cd9021c24cdbea1c3c12c966073708e83db60c2","analyzedAt":"2026-08-12T22:14:19.293Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}