Skip to content

Array field with the defaultValue gives "The following field is invalid: id" error #11871

Open

Description

@simeiko

Describe the Bug

I have a collection, let's call it myCollection, with an array-type field named myItems that has a specified defaultValue. Although the field is optional in my case, most of my collection items will have at least four elements in that array. It can be a bit tedious to click "Add item" multiple times, especially since the UI animation takes some time. As a result, I decided to always have four elements in the array field.

However, when trying to quickly add multiple collection items, I encounter the error: "The following field is invalid: id." Additionally, this issue interferes with the Postgres serial IDs, causing the "failed" IDs to be skipped.

Here is the code snippet:

export const MyCollection: CollectionConfig = {
  slug: 'myCollection',
  versions: {
    drafts: true,
    maxPerDoc: 100
  },
  admin: {
    useAsTitle: 'name'
  },
  fields: [
    {
      type: 'tabs',
      tabs: [
        {
          label: 'General',
          fields: [
            {
              name: 'name',
              type: 'text',
              required: true
            },
          ]
        },
        {
          label: 'Content',
          fields: [
            // ...
            {
              name: 'myItems',
              labels: {
                singular: 'item',
                plural: 'items'
              },
              type: 'array',
              required: false,
              defaultValue: Array(4).fill({ name: '', description: '' }),
              fields: [
                {
                  name: 'name',
                  type: 'text',
                  required: true
                },
                {
                  name: 'description',
                  type: 'text',
                  required: true
                }
              ]
            },
          ]
        },
        // ...
      ]
    }
  ]
};

I did some manual investigation and it indeed looks like it tries to submit the same IDs for the array elements.

I tried using defaultValue like this defaultValue: () => Array(4).fill({ name: '', description: '' }), but it didn't work either. It would be great if we could pass-in the callback to generate default value so it doesn't re-use the same object over and over.

Reproduction Steps

See the code snippet above for reference.

  1. Go to myCollection admin page, click Create New.
  2. Type in any name, click Save Draft.
  3. Go Back in browser without refreshing the page.
  4. You get the same "Create New" page, but with all empty fields.
  5. Type in any other name and click save draft - you would get the error.

Which area(s) are affected? (Select all that apply)

Not sure, area: core

Environment Info

Payload: 3.31.0
Node: 22.11.0

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Mar 26, 2025
  2. removed
    validate-reproduction
    on Mar 26, 2025
  3. self-assigned this
    on Mar 28, 2025
  4. removed
    status: needs-triage
    on Mar 28, 2025
  5. omaroubari commented on May 15, 2025

    @omaroubari

    were you able to resolve it?

  6. simeiko commented on May 17, 2025

    @simeiko
    Author

    were you able to resolve it?

    As a workaround, I'm performing a full page refresh (F5), which works fine for now. However, a proper fix would still be appreciated.

  7. androbro commented on Jun 16, 2025

    @androbro

    i also have this issue, ive dropped the database multiple times now to have it fixed. but after a while it just comes back.

  8. MacPiston commented on Aug 29, 2025

    @MacPiston

    I'm encountering it frequently - the only solution is to just refresh the page

  9. alexanderkalachev commented on Sep 10, 2025

    @alexanderkalachev

    Same here

  10. leosequani commented on Dec 9, 2025

    @leosequani

    Same

  11. georgeyasbic commented on Dec 11, 2025

    @georgeyasbic

    Im experiencing the same issue too.

  12. anhdd-kuro commented on Dec 19, 2025

    @anhdd-kuro

    Issues happen again, I Think this is critical , why no response from the team

  13. jstarstech commented on Dec 22, 2025

    @jstarstech

    Same here

  14. adrianoresende commented on Jan 11, 2026

    @adrianoresende

    Same here, it is impossible to update the page.

  15. adrianoresende commented on Jan 11, 2026

    @adrianoresende

    I fixed it by deleting all versions on the affected block.
    i.e., The error is with a block, ForWhom, so I deleted all versions on _pages_v_blocks_for_whom and deleted some relation parent that doesn't exist anymore on pages_blocks_for_whom_{array}_list where array is a list inside of block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions