-
-
Notifications
You must be signed in to change notification settings - Fork 145
fix(orm): fallback to compact temp aliases for overlong names #2425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ymc9
merged 7 commits into
zenstackhq:dev
from
pkudinov:fix/issue-2424-temp-alias-safety-fallback
Mar 6, 2026
+212
−7
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6a3d3a
fix(orm): fallback to compact temp aliases for overlong names
pkudinov ff685cd
refactor(orm): move temp alias length check into transformer
pkudinov 5ec19f3
chore(orm): validate temp alias maxIdentifierLength option
pkudinov 560c557
fix(orm): use utf-8 byte length for temp alias limit
pkudinov 6cb0088
perf(orm): short-circuit temp alias length traversal
pkudinov 76e9656
refactor(orm): inline temp alias overflow detection in transformer
pkudinov a19822b
refactor: further simplify long name processing
ymc9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/orm/src/client/executor/temp-alias-transformer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| describe('Regression for issue #2424', () => { | ||
| it('deep nested include with PolicyPlugin works with non-compact alias mode', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Store { | ||
| id String @id | ||
| customerOrders CustomerOrder[] | ||
| productCatalogItems ProductCatalogItem[] | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model CustomerOrder { | ||
| id String @id | ||
| storeId String | ||
| store Store @relation(fields: [storeId], references: [id], onDelete: Cascade) | ||
| customerOrderPaymentSummary CustomerOrderPaymentSummary[] | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model CustomerOrderPaymentSummary { | ||
| id String @id | ||
| customerOrderId String | ||
| customerOrder CustomerOrder @relation(fields: [customerOrderId], references: [id], onDelete: Cascade) | ||
| customerOrderPaymentSummaryLine CustomerOrderPaymentSummaryLine[] | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model PaymentTransaction { | ||
| id String @id | ||
| customerOrderPaymentSummaryLine CustomerOrderPaymentSummaryLine[] | ||
| paymentTransactionLineItem PaymentTransactionLineItem[] | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model CustomerOrderPaymentSummaryLine { | ||
| customerOrderPaymentSummaryId String | ||
| lineIndex Int | ||
| paymentTransactionId String | ||
| customerOrderPaymentSummary CustomerOrderPaymentSummary @relation(fields: [customerOrderPaymentSummaryId], references: [id], onDelete: Cascade) | ||
| paymentTransaction PaymentTransaction @relation(fields: [paymentTransactionId], references: [id], onDelete: Cascade) | ||
| @@id([customerOrderPaymentSummaryId, lineIndex]) | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model ProductCatalogItem { | ||
| storeId String | ||
| sku String | ||
| store Store @relation(fields: [storeId], references: [id], onDelete: Cascade) | ||
| paymentTransactionLineItem PaymentTransactionLineItem[] | ||
| @@id([storeId, sku]) | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model InventoryReservation { | ||
| id String @id | ||
| paymentTransactionLineItem PaymentTransactionLineItem[] | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model PaymentTransactionLineItem { | ||
| paymentTransactionId String | ||
| lineNumber Int | ||
| storeId String | ||
| productSku String | ||
| inventoryReservationId String? | ||
| paymentTransaction PaymentTransaction @relation(fields: [paymentTransactionId], references: [id], onDelete: Cascade) | ||
| productCatalogItem ProductCatalogItem @relation(fields: [storeId, productSku], references: [storeId, sku]) | ||
| inventoryReservation InventoryReservation? @relation(fields: [inventoryReservationId], references: [id], onDelete: SetNull) | ||
| @@id([paymentTransactionId, lineNumber]) | ||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| { provider: 'postgresql', useCompactAliasNames: false }, | ||
| ); | ||
|
|
||
| const rawDb = db.$unuseAll(); | ||
|
|
||
| await rawDb.store.create({ data: { id: 'store_1' } }); | ||
| await rawDb.customerOrder.create({ data: { id: 'order_1', storeId: 'store_1' } }); | ||
| await rawDb.customerOrderPaymentSummary.create({ data: { id: 'summary_1', customerOrderId: 'order_1' } }); | ||
| await rawDb.paymentTransaction.create({ data: { id: 'payment_1' } }); | ||
| await rawDb.customerOrderPaymentSummaryLine.create({ | ||
| data: { | ||
| customerOrderPaymentSummaryId: 'summary_1', | ||
| lineIndex: 0, | ||
| paymentTransactionId: 'payment_1', | ||
| }, | ||
| }); | ||
| await rawDb.productCatalogItem.create({ data: { storeId: 'store_1', sku: 'sku_1' } }); | ||
| await rawDb.inventoryReservation.create({ data: { id: 'reservation_1' } }); | ||
| await rawDb.paymentTransactionLineItem.create({ | ||
| data: { | ||
| paymentTransactionId: 'payment_1', | ||
| lineNumber: 0, | ||
| storeId: 'store_1', | ||
| productSku: 'sku_1', | ||
| inventoryReservationId: 'reservation_1', | ||
| }, | ||
| }); | ||
|
|
||
| const result = await db.customerOrderPaymentSummary.findUnique({ | ||
| where: { id: 'summary_1' }, | ||
| include: { | ||
| customerOrder: true, | ||
| customerOrderPaymentSummaryLine: { | ||
| include: { | ||
| paymentTransaction: { | ||
| include: { | ||
| paymentTransactionLineItem: { | ||
| include: { | ||
| productCatalogItem: true, | ||
| inventoryReservation: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ | ||
| id: 'summary_1', | ||
| customerOrder: { | ||
| id: 'order_1', | ||
| storeId: 'store_1', | ||
| }, | ||
| customerOrderPaymentSummaryLine: [ | ||
| { | ||
| customerOrderPaymentSummaryId: 'summary_1', | ||
| lineIndex: 0, | ||
| paymentTransactionId: 'payment_1', | ||
| paymentTransaction: { | ||
| id: 'payment_1', | ||
| paymentTransactionLineItem: [ | ||
| { | ||
| paymentTransactionId: 'payment_1', | ||
| lineNumber: 0, | ||
| storeId: 'store_1', | ||
| productSku: 'sku_1', | ||
| inventoryReservationId: 'reservation_1', | ||
| productCatalogItem: { | ||
| storeId: 'store_1', | ||
| sku: 'sku_1', | ||
| }, | ||
| inventoryReservation: { | ||
| id: 'reservation_1', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| await db.$disconnect(); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.