fix(orm): split jsonb_build_object calls exceeding PostgreSQL 100-arg limit#2554
fix(orm): split jsonb_build_object calls exceeding PostgreSQL 100-arg limit#2554
Conversation
… limit When including a nested relation with 51+ columns, the generated jsonb_build_object call would exceed PostgreSQL's FUNC_MAX_ARGS limit of 100 (error code 54023). Fix by chunking the key-value pairs into groups of 50 and concatenating the resulting jsonb objects with ||. Fixes #2524 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughModified Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @ymc9's task —— View job Code Review: PostgreSQL jsonb_build_object 100-argument limit fixSummary: This PR successfully addresses PostgreSQL's ✅ Code Quality & Best PracticesStrong Points:
Minor Suggestion: private buildJsonObjectChunk(entries: [string, Expression<unknown>][]) {
return this.eb.fn('jsonb_build_object', entries.flatMap(([k, v]) => [sql.lit(k), v]));
}✅ Correctness & Bug AnalysisThe implementation looks correct:
✅ Performance ConsiderationsPositive aspects:
Performance is optimal for this constraint. The alternative (multiple queries) would be significantly slower. ✅ SecurityNo security concerns identified:
✅ Test CoverageExcellent test coverage in
Test quality: The test model with 51 columns precisely targets the edge case and validates the fix works end-to-end. 📝 Minor Recommendations
✅ Overall AssessmentThis is a high-quality fix that elegantly solves a real PostgreSQL limitation. The implementation is:
Recommendation: Approve - This PR is ready for merge. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/regression/test/issue-2524.test.ts (1)
90-92: Strengthen the assertion to verify fields beyond the first 50 pairs are returned.Current checks confirm row counts, but not that chunk-merged JSON contains tail fields. Add a check for
col51to guard against partial-object regressions.Proposed test enhancement
expect(result).toHaveLength(1); expect(result[0].opportunities).toHaveLength(1); + expect(result[0].opportunities[0].col51).toBe('');🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/regression/test/issue-2524.test.ts` around lines 90 - 92, Add an assertion that verifies the merged JSON includes fields beyond the first 50 pairs by checking for the presence/value of col51: after the existing expectations on result and result[0].opportunities, assert that result[0].opportunities[0].row.col51 is defined (or equals the expected value) so the test fails if the tail fields are omitted; update the test block that uses result/opportunities/row to include this new check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/regression/test/issue-2524.test.ts`:
- Around line 90-92: Add an assertion that verifies the merged JSON includes
fields beyond the first 50 pairs by checking for the presence/value of col51:
after the existing expectations on result and result[0].opportunities, assert
that result[0].opportunities[0].row.col51 is defined (or equals the expected
value) so the test fails if the tail fields are omitted; update the test block
that uses result/opportunities/row to include this new check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f06906f1-3d3c-4fe4-bc6e-2ae6a20f5533
📒 Files selected for processing (2)
packages/orm/src/client/crud/dialects/postgresql.tstests/regression/test/issue-2524.test.ts
Summary
FUNC_MAX_ARGSlimit is 100.jsonb_build_objecttakes key-value pairs, so a relation with 51+ columns produces 102+ arguments and crashes with error code 54023jsonbobjects with the||operatorFixes #2524
Test plan
tests/regression/test/issue-2524.test.tspasses against a real PostgreSQL instancejsonb_build_objectcall as before)🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests