#payload.update not working on multi-tenant global with localized fields

1 messages · Page 1 of 1 (latest)

thorn prairie
#

I am encountering a weird problem whilst trying to migrate my current data to default locale. The solution I've built works perfectly for every other collection except my layouts, which is a collection that is specified as a isGlobal: true under my multi-tenant plugin configuration.

I am doing this migration in 2 steps, fetching the current data and persisting it in a old_data.json file, then updating all collections that have some localized: true field, either directly or somewhere nested in blocks, arrays, etc.

Any idea what might be causing the problem. The only difference between my pages and layout collection is that layout is specified as a global in my multi-tenant config. Any help is appreciated 🙏

// migration_one.ts
export async function up({ payload }: MigrateUpArgs): Promise<void> {
  const [pages, layouts] =
    await Promise.all([
      payload
        .find({
          collection: "pages",
          limit: 0,
          depth: 0,
        })
        .then((res) => res.docs),
      payload
        .find({
          collection: "layout",
          limit: 0,
          depth: 0,
        })
        .then((res) => res.docs),
    ]);


  const data = {
    pages,
    layouts,
  };
  
  // saves data object to old_data.json so I can use it in another migration
  await promises.writeFile("temp/old_data.json", JSON.stringify(data, null, 2));
}
// migration_two.ts
export async function up({ payload }: MigrateUpArgs): Promise<void> {
  const data = JSON.parse(fileData) as {
    pages: Page[];
    layouts: Layout[];
  };
  
  // this works as expected
  for (const page of data.pages) {
    await payload.update({
      collection: "pages",
      id: page.id,
      locale: "en",
      data: page,
    });
  }
  // this does not work as expected
  for (const layout of data.layouts) {
    await payload.update({
      collection: "layout",
      id: layout.id,
      locale: "en",
      data: layout,
    });
  }
}
thorn prairie
#

I am going to bump this by saying the problem was probably related to #13456, but updating to 3.53.0 which merges the PR which allegedly fixes it also breaks my migration for other collections.