Postgres caps function arguments at 100. `payload_locked_documents_rels` holds one foreign-key column per collection, and Drizzle hydrates the locked document's polymorphic relationship with a single `json_build_array(...)` over all of them. At 103 collections the query throws 54023 and every admin edit view breaks while a lock row exists. Patch drizzle-orm 0.45.2 to split the call into 100-argument groups joined with `::jsonb || ::jsonb`, mirroring the unmerged upstream PR drizzle-team/drizzle-orm#4495. Relations with 100 or fewer columns keep the original code path unchanged. Add tests/int/locked-documents-query.int.spec.ts, which creates a lock row and reads it back at depth 1 (what getIsLocked and handleFormStateLocking do). It fails on pristine drizzle with the exact 54023 error and passes with the patch.
54 lines
2.9 KiB
Diff
54 lines
2.9 KiB
Diff
diff --git a/pg-core/dialect.js b/pg-core/dialect.js
|
|
--- a/pg-core/dialect.js
|
|
+++ b/pg-core/dialect.js
|
|
@@ -1061,12 +1061,17 @@
|
|
let result;
|
|
where = and(joinOn, where);
|
|
if (nestedQueryRelation) {
|
|
- let field = sql`json_build_array(${sql.join(
|
|
- selection.map(
|
|
- ({ field: field2, tsKey, isJson }) => isJson ? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier("data")}` : is(field2, SQL.Aliased) ? field2.sql : field2
|
|
- ),
|
|
- sql`, `
|
|
- )})`;
|
|
+ const fieldChunks = [];
|
|
+ for (let i = 0; i < selection.length; i += 100) {
|
|
+ const chunk = selection.slice(i, i + 100);
|
|
+ fieldChunks.push(sql`json_build_array(${sql.join(
|
|
+ chunk.map(
|
|
+ ({ field: field2, tsKey, isJson }) => isJson ? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier("data")}` : is(field2, SQL.Aliased) ? field2.sql : field2
|
|
+ ),
|
|
+ sql`, `
|
|
+ )})`);
|
|
+ }
|
|
+ let field = fieldChunks.length === 1 ? fieldChunks[0] : fieldChunks.reduce((acc, chunk) => sql`${acc}::jsonb || ${chunk}::jsonb`);
|
|
if (is(nestedQueryRelation, Many)) {
|
|
field = sql`coalesce(json_agg(${field}${orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : void 0}), '[]'::json)`;
|
|
}
|
|
diff --git a/pg-core/dialect.cjs b/pg-core/dialect.cjs
|
|
--- a/pg-core/dialect.cjs
|
|
+++ b/pg-core/dialect.cjs
|
|
@@ -1063,12 +1063,17 @@
|
|
let result;
|
|
where = (0, import_sql.and)(joinOn, where);
|
|
if (nestedQueryRelation) {
|
|
- let field = import_sql2.sql`json_build_array(${import_sql2.sql.join(
|
|
- selection.map(
|
|
- ({ field: field2, tsKey, isJson }) => isJson ? import_sql2.sql`${import_sql2.sql.identifier(`${tableAlias}_${tsKey}`)}.${import_sql2.sql.identifier("data")}` : (0, import_entity.is)(field2, import_sql2.SQL.Aliased) ? field2.sql : field2
|
|
- ),
|
|
- import_sql2.sql`, `
|
|
- )})`;
|
|
+ const fieldChunks = [];
|
|
+ for (let i = 0; i < selection.length; i += 100) {
|
|
+ const chunk = selection.slice(i, i + 100);
|
|
+ fieldChunks.push(import_sql2.sql`json_build_array(${import_sql2.sql.join(
|
|
+ chunk.map(
|
|
+ ({ field: field2, tsKey, isJson }) => isJson ? import_sql2.sql`${import_sql2.sql.identifier(`${tableAlias}_${tsKey}`)}.${import_sql2.sql.identifier("data")}` : (0, import_entity.is)(field2, import_sql2.SQL.Aliased) ? field2.sql : field2
|
|
+ ),
|
|
+ import_sql2.sql`, `
|
|
+ )})`);
|
|
+ }
|
|
+ let field = fieldChunks.length === 1 ? fieldChunks[0] : fieldChunks.reduce((acc, chunk) => import_sql2.sql`${acc}::jsonb || ${chunk}::jsonb`);
|
|
if ((0, import_entity.is)(nestedQueryRelation, import_relations.Many)) {
|
|
field = import_sql2.sql`coalesce(json_agg(${field}${orderBy.length > 0 ? import_sql2.sql` order by ${import_sql2.sql.join(orderBy, import_sql2.sql`, `)}` : void 0}), '[]'::json)`;
|
|
}
|