-
-
Notifications
You must be signed in to change notification settings - Fork 104
fix: using auth()
in @default()
is not effective for createManyAndReturn
#1727
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
Conversation
WalkthroughWalkthroughThe changes introduce a new action, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant API
participant PolicyHandler
participant NestedWriteVisitor
participant Database
User->>API: Request createManyAndReturn
API->>PolicyHandler: Process request
PolicyHandler->>NestedWriteVisitor: Handle createManyAndReturn
NestedWriteVisitor->>Database: Create multiple records
Database-->>NestedWriteVisitor: Return created records
NestedWriteVisitor-->>PolicyHandler: Return created records
PolicyHandler-->>API: Return created records
API-->>User: Respond with created records
Assessment against linked issues
Possibly related PRs
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional comments not posted (5)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- packages/runtime/src/cross/nested-write-visitor.ts (1 hunks)
- packages/runtime/src/cross/types.ts (1 hunks)
- packages/runtime/src/enhancements/node/default-auth.ts (1 hunks)
- packages/runtime/src/enhancements/node/policy/handler.ts (7 hunks)
- tests/integration/tests/enhancements/with-policy/auth.test.ts (4 hunks)
- tests/regression/tests/issue-1681.test.ts (1 hunks)
Additional comments not posted (11)
packages/runtime/src/cross/types.ts (1)
7-7
: LGTM!The addition of the
'createManyAndReturn'
action to thePrismaWriteActions
array is a valid change. It introduces a new type of write operation for creating multiple records and returning the created records. The change is consistent with the existing pattern and is well-documented in the AI-generated summary.tests/regression/tests/issue-1681.test.ts (1)
3-28
: LGTM!The test case is well-structured and provides good coverage for the regression issue mentioned in the PR objectives. It validates the functionality of creating users and posts using the
createMany
andcreateManyAndReturn
methods, and ensures that theauthorId
field of thePost
model defaults to the ID of the authenticated user.The test case follows a logical flow and uses appropriate assertions to validate the expected behavior. It enhances the schema with a user ID, creates a new user, and then verifies that posts can be created successfully with the correct
authorId
.Overall, the test case is comprehensive and effectively addresses the regression issue.
packages/runtime/src/enhancements/node/default-auth.ts (1)
52-59
: Approve adding'createManyAndReturn'
toactionsOfInterest
.The addition of
'createManyAndReturn'
to theactionsOfInterest
array is a logical extension of theDefaultAuthHandler
's preprocessing functionality. This change allows the handler to process and potentially modify the write payload for the newcreateManyAndReturn
action.Verify that the
preprocessWritePayload
method correctly handles thecreateManyAndReturn
action. Run the following script to check ifcreateManyAndReturn
is processed by theNestedWriteVisitor
:packages/runtime/src/cross/nested-write-visitor.ts (1)
172-172
: LGTM!The addition of the
createManyAndReturn
case to thedoVisit
method is a logical extension of the existing functionality. It follows the established pattern and is consistent with the provided summary.tests/integration/tests/enhancements/with-policy/auth.test.ts (3)
393-396
: Tests validatecreateMany
andcreateManyAndReturn
with default overridesThe added tests correctly ensure that the
authorName
override is respected when using bothcreateMany
andcreateManyAndReturn
, confirming that explicitly provided values take precedence over default values derived fromauth()
.
422-427
: Consistent testing of default value overrides in batch operationsThe tests appropriately verify that
createMany
andcreateManyAndReturn
do not override explicitly providedauthorName
values with defaults fromauth()
. This confirms the intended behavior in batch operations.
654-666
: Effective testing of defaultauth()
values in various create operationsThe tests accurately validate that default
auth()
values are correctly applied increate
,createMany
, andcreateManyAndReturn
operations, even when associating posts with stats. This ensures that the default authentication context is consistently enforced across different methods.packages/runtime/src/enhancements/node/policy/handler.ts (4)
15-15
: Import Statement Addition ApprovedThe addition of
getModelInfo
to the imports is appropriate and necessary for the implementation ofhasRelationFieldsInPayload
.
439-443
: Enhancement ofcreateMany
Method ApprovedThe conditional logic to determine whether to convert
createMany
to individualcreate
operations improves the handling of nested creates and post-write checks. The transaction management is correctly implemented.Also applies to: 448-448
475-481
: Enhancement ofcreateManyAndReturn
Method ApprovedThe updates effectively manage the decision to perform direct
createManyAndReturn
or to handle each creation individually with proper transaction support and post-write checks. Error handling and result processing are correctly addressed.Also applies to: 491-497
581-586
: Modification ofdoCreateMany
Method ApprovedPassing the
action
parameter enhances the clarity of log messages and ensures that the method can handle different actions appropriately. The logging at line 602 correctly reflects the action being performed, aiding in debugging and monitoring.Also applies to: 602-602
Fixes #1681