fix(policy): compact relation subquery aliases to avoid PostgreSQL identifier truncation - #2849
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: zenstackhq/zenstack/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe policy transformer now marks generated relation aliases as temporary. New PostgreSQL end-to-end tests cover self-relations, nested predicates, tenant enforcement, many-to-many access, and long relation names. ChangesRelation alias isolation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No concrete merge-blocking defect was identified in the changed alias handling or its regression coverage. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
…et compacted
Relation aliases were built as `${field}$${counter}` without the temp alias
prefix, so the executor's `TempAliasTransformer` left them untouched. On
PostgreSQL a relation field name of 62+ chars made every alias derived
from it truncate to the same 63-byte identifier, producing either a
"table name specified more than once" error or, across nested subqueries,
the very self-relation shadowing this branch set out to fix.
Route the aliases through `QueryUtils.tmpAlias()` so the existing
transformer compacts them (or shortens them when they exceed the
identifier limit if `useCompactAliasNames` is off). Add a PostgreSQL
regression test with an over-long self many-to-many relation field.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
0efd7ae to
9040abf
Compare
Summary
Follow-up to #2845, addressing a CodeRabbit finding.
Relation subquery aliases in the policy expression transformer were built as
${field}$${counter}without the temp alias prefix, so the executor's existingTempAliasTransformerleft them untouched. On PostgreSQL a relation field name of 62+ chars made every alias derived from it truncate to the same 63-byte identifier, producingtable name ... specified more than onceor, across nested subqueries, re-introducing the self-relation shadowing that #2845 fixed.newRelationAliasnow routes throughQueryUtils.tmpAlias(), so the existing transformer compacts the aliases (or shortens only over-long ones whenuseCompactAliasNamesis off). No new shortening scheme is introduced.Tests
Added a PostgreSQL regression test in
tests/e2e/orm/policy/self-relation.test.tswith a 70-char self many-to-many relation field and a nested collection predicate, run withuseCompactAliasNames: falseto exercise the length guard. It fails before this change with the truncation error and passes after.Ran
tests/e2e/orm/policy,tests/regression, andpackages/ormsuites on SQLite, plus policy plugin lint.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests