appsmithorg/appsmith · error · Error

updateModel expects an object as parameter

Error message

updateModel expects an object as parameter

What it means

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.

Source

Thrown at app/client/src/widgets/wds/WDSCustomWidget/component/customWidgetscript.js:239

          if (typeof fn !== "function") {
            throw new Error("onModelChange expects a function as parameter");
          }

          modelSubscribers.push(fn);
          fn(window.appsmith.model);

          return () => {
            // Unsubscribe from model changes
            const index = modelSubscribers.indexOf(fn);

            if (index > -1) {
              modelSubscribers.splice(index, 1);
            }
          };
        },
        updateModel: (obj) => {
          if (!obj || typeof obj !== "object") {
            throw new Error("updateModel expects an object as parameter");
          }

          appsmith.model = Object.assign(
            Object.assign({}, appsmith.model),
            obj,
          );

          // Send an update model message to the parent
          channel.postMessage(EVENTS.CUSTOM_WIDGET_UPDATE_MODEL, obj);
        },
        triggerEvent: (eventName, contextObj) => {
          if (typeof eventName !== "string") {
            throw new Error("eventName should be a string");
          } else if (contextObj && typeof contextObj !== "object") {
            throw new Error("contextObj should be an object");
          }

          // Send a trigger event message to the parent

View on GitHub (pinned to 8cd9021c24)

Solutions

  1. Pass a plain object literal: appsmith.updateModel({ selectedId: id }).
  2. Default optional patches: appsmith.updateModel(patch ?? {}).
  3. Assemble the patch in a typed local first so it can never be a primitive.
  4. Wrap arrays under a key: appsmith.updateModel({ rows: rowsArray }).

Example fix

// before
appsmith.updateModel(form.value); // form.value is a string

// after
appsmith.updateModel({ value: form.value });
Defensive patterns

Strategy: validation

Validate before calling

const patch = maybePatch ?? {};
if (typeof patch !== 'object' || patch === null) {
  throw new TypeError('updateModel needs a plain object');
}
appsmith.updateModel(patch);

Type guard

const isPlainObject = (v) =>
  v !== null && typeof v === 'object' && !Array.isArray(v);

// usage
if (isPlainObject(patch)) appsmith.updateModel(patch);

Try / catch

try {
  appsmith.updateModel(patch ?? {});
} catch (e) {
  console.error('updateModel rejected patch:', e.message);
}

Prevention

When it happens

Trigger: Calling appsmith.updateModel(null), appsmith.updateModel(undefined), appsmith.updateModel('foo'), appsmith.updateModel(42), or appsmith.updateModel() with no argument inside the WDS widget.

Common situations: 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.

Related errors


AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12). Data as JSON: /api/errors/a4ba66dac7bd6140. Report an issue: GitHub.