Somewhat unhelpful validation error for missing value for a similarly-named schema prop

Error appearing in sync table config:

Syncing Table Name from Test Pack failed - ‘id’ property is undefined or null

This is due to a prop being present in schema, having the same name as the id prop but with some case differences, but not present in returned result. The error is a red herring which makes it difficult to debug (the pack thinks that the other cased prop is the id prop, and that other cased prop is indeed undefined in the result, but this is not obvious).

MRE:

import * as coda from "@codahq/packs-sdk";

export const pack = coda.newPack();

pack.addDynamicSyncTable({
  name: "TableName",
  
  listDynamicUrls: async function () {
    return [{
        display: "foo",
        value: "foo",
      }];
  },
  getName: async function () {
    return "Foo";
  },
  getDisplayUrl: async function (context) {
    return context.sync!.dynamicUrl!;
  },
  getSchema: async function (context) {
    return coda.makeObjectSchema({
      properties: {
        name: {
          type: coda.ValueType.String,
          description: "The name."
        },
        rowUrl: {
          type: coda.ValueType.String,
          codaType: coda.ValueHintType.Url,
          description: "the URL"
        },
        RowUrl: { type: coda.ValueType.String, description: "the URL" }, // bug part 1
      },
      idProperty: "rowUrl",
      displayProperty: "name",
      featuredProperties: ["name", "rowUrl"],
    });
  },
  identityName: "afoo",
  formula: {
    name: "Foo",
    description: "",
    parameters: [
      coda.makeParameter({
        type: coda.ParameterType.String,
        name: "nonOptString",
        description: "",
      }),
      coda.makeParameter({
        type: coda.ParameterType.String,
        name: "optString",
        description: "",
        optional: true,
      }),
      coda.makeParameter({
        type: coda.ParameterType.Boolean,
        name: "optBoolean",
        description: "",
        optional: true,
        suggestedValue: false
      })],
      execute: async function (params, context) {
        return { result: [
          {name: "foo", rowUrl: "bar"}, // bug part 2
          {name: "foo2", rowUrl: "baz"} // and here
        ] };
      }
    }
});

Thanks for reporting @loucadufault! I think the core issue is that you have two properties that when normalized collapse to the same name. When there is no idProperty involved you’ll see that only one of them will end up in the result object in the doc. I don’t think we intend to support this setup but don’t yet have enough validation to catch it early. I’ll talk to the engineering team to see if we can improve that.

1 Like