Skip to content

Error adding a new item to repeatable component #11980

@chadwithuhc

Description

@chadwithuhc

Bug report

Describe the bug

I am trying to add a new item to a repeatable component field through an API PUT /api/[api-name]/:id. I expected to be able to push a new item on the array without an ID and it will be created, but I receive an error instead. I am not sure if this is a bug or my misunderstanding of the API.

Steps to reproduce the behavior

Example of Lists Content Type
Example of Lists Content Type

  1. Inside my beforeUpdate() lifecycle hook for my Lists API,
  2. I try to add a new item to my existing items array by using:
event.params.data.items.push({
  title: "Washcloths",
  checked: true
})
  1. I can see it is properly added to the data
// event.params.data
{
  title: 'Craigslist',
  items: [ { title: 'Washcloths', checked: true } ],
  updatedAt: 2021-12-22T00:21:36.488Z
}
  1. Then I get the error error: Invalid id, expected a string or integer, got [object Object] once it is run
Error: Invalid id, expected a string or integer, got [object Object]
    at node_modules/@strapi/database/lib/entity-manager.js:25:15

Expected behavior

I would expect it to create a new item for me.

System

  • Node.js version: v16.13.0
  • NPM version: 8.1.0
  • Strapi version: 4.0.0
  • Database: sqlite3
  • Operating system: Mac OS Monterrey

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: mediumIf it breaks the basic use of the product but can be worked aroundsource: core:strapiSource is core/strapi packagestalestale-before-2022status: confirmedConfirmed by a Strapi Team member or multiple community members

    Type

    No type

    Projects

    Status

    Fixed/Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions