strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable and developer-first.
https://strapi.io
Other
62.78k stars 7.88k forks source link

Entity Service: Failure to delete or update repeatable components when they are greater than 100 #15834

Open nicoXXXXXtitan opened 1 year ago

nicoXXXXXtitan commented 1 year ago

Hello I opened this issue after the discovery of a bug in a custom plugin (see the description below). It turns out that the bug concerns everyone because it is also present in the content manager. To make it simple, here is the bug: If I have more than 100 repeatable components and I want to delete them all, the operation is not possible and I have this error.

error: Undefined binding(s) detected when compiling WHERE. Undefined column(s): [t0.id] query: where `t0`.`entity_id` = ? and `t0`.`id` > ? and 1 = ? and `t0`.`field` = ?
Error: Undefined binding(s) detected when compiling WHERE. Undefined column(s): [t0.id] query: where `t0`.`entity_id` = ? and `t0`.`id` > ? and 1 = ? and `t0`.`field` = ?

To get around the problem, I have to delete them by packages lower than 100.

1st version of the issue ⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️

Hello ! We have a content type named pagelists composed of several components. The component we update is the pagelist_listing_products_order. It is repeatable.

// ..../api/pagelist/content-types/pagelist/schema.json

{
 "kind": "collectionType",
 "collectionName": "pagelists",
 "info": {
   "singularName": "pagelist",
   "pluralName": "pagelists",
   "displayName": "Page Liste",
   "description": ""
 },
 "options": {
   "draftAndPublish": true
 },
 "pluginOptions": {},
 "attributes": {
   "pagelist_listing_products_order": {
     "type": "component",
     "repeatable": true,
     "component": "page-liste.page-liste-listing-produits"
   }
 }
}

And that of the component :

// ..../src/components/page-liste/page-liste-listing-produits.json

{
 "collectionName": "components_page_liste_page_liste_listing_produits",
 "info": {
   "displayName": "Page Liste - Listing produits ordre",
   "icon": "bus",
   "description": ""
 },
 "options": {},
 "attributes": {
   "pagelist_listing_products_reference": {
     "type": "string"
   },
   "pagelist_listing_products_position": {
     "type": "integer"
   }
 }
}

In a home-made plugin, we update the pagelist_listing_products_order component following the Strapi doc https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/entity-service/components-dynamic-zones.html#creation

The doc says that:

strapi.entityService.update('api::article.article', 1, {
  data: {
    myComponent: {
      id: 1, // will update component with id: 1 (if not specified, would have deleted it and created a new one)
      foo: 'bar',
    },
  },
});

Our code looks like this:

strapi.entityService.update('api::pagelist.pagelist', pageListId, {
           data: {
               pagelist_listing_products_order: products
           },
         });

In the variable products we have this:

  {
    pagelist_listing_products_reference: '1506IESE05A',
    pagelist_listing_products_position: 1
  },
  {
    pagelist_listing_products_reference: '1506IggESE05A',
    pagelist_listing_products_position: 2
  },
  {
    pagelist_listing_products_reference: '15gg06IESE05A',
    pagelist_listing_products_position: 2
  },
// etc....... 150x

We didn't put the identifier because the example in the doc says that if not specified, would have deleted it and created a new one For several months we have been updating this repetable component in this way. It has grown lately by our editors, more than 100 on several of our contentype pagelist. When we save we get this error:

error: Undefined binding(s) detected when compiling WHERE. Undefined column(s): [t0.id] query: where `t0`.`entity_id` = ? and `t0`.`id` > ? and 1 = ? and `t0`.`field` = ?
Error: Undefined binding(s) detected when compiling WHERE. Undefined column(s): [t0.id] query: where `t0`.`entity_id` = ? and `t0`.`id` > ? and 1 = ? and `t0`.`field` = ?

After long debugging phases, it turns out that if I have up to 99 repeatable components, I have no errors when updating the component. From 100 components, the update is not possible. Strapi can't delete each component components_page_listing_products.

To solve the bug, we now provide it with the id.

  {
    pagelist_listing_products_reference: '1506IESE05A',
    pagelist_listing_products_position: 1,
     id: 50874
  },

To summarize: If we update a repeatable component without providing it with an id AND there are less than 100 repeatable components, the registration is possible. If we have more than 100 repeatable components, we must absolutely provide its id for a registration without bug.

I hope I have been clear enough. Thank you and have a nice day!

nicoXXXXXtitan commented 1 year ago

I have updated the issue.

usuallyno commented 1 year ago

thank you @nicoXXXXXtitan! you save us hours of debugging 💯

nicoXXXXXtitan commented 1 year ago

With pleasure! The debug had been long :smile: I hope Strapi will take care of it soon!

presto2116 commented 1 year ago

Chiming in on this issue, we are encountering the same thing. we use @strapi/plugin-i18n and have a repeatable component in one of our collection types. When a author attempts to "Fill in from another locale", it fails if the repeatable component is greater than 100. after many hours of debugging, we also arrived at the above issue. seems like a strange constraint as its quite normal to have very large repeatable components.

IvanWala commented 11 months ago

Something new about this?

jonathanafranio commented 4 months ago

news?