Bulk Relationship Update: bind message has 2608 parameter formats but 0 parameters

System Information
  • Strapi Version: v.4.5.4
  • Operating System: Linux
  • Database: PostgreSQL
  • Node Version: 16.17.1

When creating a bulk number of relationships with one entry and many others, I’m receiving the following error:

, $68118, $68119, $68120), ($68121, $68122, $68123, $68124), ($68125, $68126, $68127, $68128), ($68129, $68130, $68131, $68132), ($68133, $68134, $68135, $68136), ($68137, $68138, $68139, $68140), ($68141, $68142, $68143, $68144) on conflict ("foo_id", "bar_id") do update set "foo_order" = excluded."foo_order" returning "id" - bind message has 2608 parameter formats but 0 parameters
    at Parser.parseErrorMessage (/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

The entry already has 16,034 relationships and I’m trying to add another 1,022. To do this, we’ve implemented a button based on the Filtered results to update an entry with a bulk number of relationships to other entries.

During the update, we’re removing all unnecessary data except for the id:

foo [
  { id: 757 },  { id: 736 },  { id: 2773 }, { id: 778 },  { id: 2794 },
  { id: 820 },  { id: 841 },  { id: 862 },  { id: 883 },  { id: 904 },
  { id: 925 },  { id: 946 },  { id: 967 },  { id: 988 },  { id: 1009 },
  { id: 1030 }, { id: 1051 }, { id: 1072 }, { id: 1093 }, { id: 1114 },
  { id: 1135 }, { id: 1156 }, { id: 1177 }, { id: 1198 }, { id: 1219 },
  { id: 1240 }, { id: 1261 }, { id: 1282 }, { id: 1303 }, { id: 1324 },
  { id: 1345 }, { id: 1366 }, { id: 1387 }, { id: 1408 }, { id: 1429 },
  { id: 1450 }, { id: 1471 }, { id: 1492 }, { id: 1513 }, { id: 1534 },
  { id: 1555 }, { id: 1576 }, { id: 1597 }, { id: 1618 }, { id: 1639 },
  { id: 1660 }, { id: 1681 }, { id: 1702 }, { id: 1723 }, { id: 1744 },
  { id: 1765 }, { id: 1786 }, { id: 1807 }, { id: 1828 }, { id: 1849 },
  { id: 1870 }, { id: 1891 }, { id: 1912 }, { id: 1933 }, { id: 1954 },
  { id: 1975 }, { id: 1996 }, { id: 2017 }, { id: 2038 }, { id: 2059 },
  { id: 2080 }, { id: 2101 }, { id: 2122 }, { id: 2143 }, { id: 2164 },
  { id: 2185 }, { id: 2206 }, { id: 2227 }, { id: 2248 }, { id: 2269 },
  { id: 2290 }, { id: 2311 }, { id: 2332 }, { id: 2353 }, { id: 2374 },
  { id: 2395 }, { id: 2416 }, { id: 2437 }, { id: 2458 }, { id: 2479 },
  { id: 2500 }, { id: 2521 }, { id: 2542 }, { id: 2563 }, { id: 2584 },
  { id: 2605 }, { id: 2626 }, { id: 2647 }, { id: 2668 }, { id: 2689 },
  { id: 2710 }, { id: 2731 }, { id: 2752 }, { id: 2815 }, { id: 2836 },
  ... 16936 more items
]

With this array, we’re updating the entry like so:

    return await strapi.entityService.update(
      BAR_UID,
      barId,
      {
        data: {
          foo: foo,
        },
      }
    );

All works well until we get to 16,000+ relationships.

An alternative solution is to do the query in reverse, instead of adding 16,000+ bar to foo, we add the relationship of foo to bar. But this will be very slow as it will be 16,000+ individual queries instead of 1 large query.