Skip to content
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

fix(delegate): base fields not properly wrapped inside relation layer when injected from policies #1736

Merged
merged 2 commits into from
Sep 23, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 23, 2024

Fixes #1734

Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

Walkthrough

The pull request introduces several updates across multiple files, including enhancements to the changelog, a version increment in the build.gradle.kts file, modifications to the DelegateProxyHandler class to improve its functionality, and the addition of a regression test for schema behavior regarding access control and visibility of inherited fields. These changes collectively address validation issues and enhance model handling capabilities.

Changes

Files Change Summary
packages/ide/jetbrains/CHANGELOG.md Updates to the changelog for multiple versions, detailing new features, fixes, and enhancements.
packages/ide/jetbrains/build.gradle.kts Version updated from "2.6.0" to "2.6.1".
packages/runtime/src/enhancements/node/delegate.ts DelegateProxyHandler class modified to enhance buildSelectIncludeHierarchy method and add createConcreteRelationIncludePayload method.
tests/regression/tests/issue-1734.test.ts New regression test added for schema behavior involving access control for fields in inherited models.

Assessment against linked issues

Objective Addressed Explanation
Validate that inherited fields from polymorphic base models are visible (1734)
Ensure that the schema correctly handles access control based on user roles (1734)

Possibly related PRs


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Outside diff range and nitpick comments (2)
packages/ide/jetbrains/CHANGELOG.md (2)

4-7: LGTM! Consider enhancing the description.

The fix addresses the issue mentioned in the PR objectives regarding base fields not being properly wrapped. This is a crucial update that resolves the problem with accessing fields defined in a base model.

Consider rephrasing the entry for clarity:

- -   ZModel validation issues when accessing fields defined in a base model from `future().` or `this.`.
+ -   Fixed ZModel validation issues when accessing fields defined in a base model using `future().` or `this.`.

21-29: LGTM! New feature and bug fix.

The addition of the check() policy rule function and the fix for formatting schemas with Unsupported type are valuable improvements.

Consider rephrasing the second entry for better wording:

- -   Fixed the issue with formatting schemas containing `Unsupported` type.
+ -   Resolved the issue with formatting schemas containing `Unsupported` type.
Tools
LanguageTool

[style] ~29-~29: Consider using a different verb for a more formal wording.
Context: ...` policy rule function. ### Fixed - Fixed the issue with formatting schemas conta...

(FIX_RESOLVE)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9fb8d5b and c9c377e.

Files ignored due to path filters (13)
  • package.json is excluded by !**/*.json
  • packages/ide/jetbrains/package.json is excluded by !**/*.json
  • packages/language/package.json is excluded by !**/*.json
  • packages/misc/redwood/package.json is excluded by !**/*.json
  • packages/plugins/openapi/package.json is excluded by !**/*.json
  • packages/plugins/swr/package.json is excluded by !**/*.json
  • packages/plugins/tanstack-query/package.json is excluded by !**/*.json
  • packages/plugins/trpc/package.json is excluded by !**/*.json
  • packages/runtime/package.json is excluded by !**/*.json
  • packages/schema/package.json is excluded by !**/*.json
  • packages/sdk/package.json is excluded by !**/*.json
  • packages/server/package.json is excluded by !**/*.json
  • packages/testtools/package.json is excluded by !**/*.json
Files selected for processing (4)
  • packages/ide/jetbrains/CHANGELOG.md (1 hunks)
  • packages/ide/jetbrains/build.gradle.kts (1 hunks)
  • packages/runtime/src/enhancements/node/delegate.ts (4 hunks)
  • tests/regression/tests/issue-1734.test.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/ide/jetbrains/build.gradle.kts
Additional context used
LanguageTool
packages/ide/jetbrains/CHANGELOG.md

[style] ~29-~29: Consider using a different verb for a more formal wording.
Context: ...` policy rule function. ### Fixed - Fixed the issue with formatting schemas conta...

(FIX_RESOLVE)

Additional comments not posted (12)
packages/ide/jetbrains/CHANGELOG.md (8)

9-13: LGTM! New feature addition.

The new path parameter for the @@validate attribute is a valuable addition, allowing for more precise error reporting.


15-19: LGTM! Important update to UUID functionality.

The update to the uuid() function to support new UUID version features from Prisma is a valuable improvement.


31-35: LGTM! Significant feature addition.

The support for comparing fields from different models in mutation policy rules is a powerful enhancement that increases the flexibility of the system.


37-42: LGTM! Important updates to improve functionality.

Both changes in this version are valuable improvements:

  1. The support for using ZModel type names as model field names increases flexibility in schema design.
  2. The update to auth() resolution to include all reachable schema files enhances the system's ability to handle complex schema structures.

44-48: LGTM! Major version release.

The release of ZenStack V2 is a significant milestone. It would be helpful to provide more details about the major changes or improvements in this version.


50-58: LGTM! Relevant fixes and feature additions.

Both changes in this version are valuable:

  1. The support for complex usage of the @@index attribute enhances the system's indexing capabilities.
  2. The fix for ZModel validation issues related to model inheritance is particularly relevant to the current PR objectives, as it addresses problems in the inheritance system, which is related to the base fields issue being fixed in the current PR.

Line range hint 60-64: LGTM! Useful developer feature.

The addition of auto-completion support inside attributes is a valuable improvement that enhances the developer experience.

Tools
LanguageTool

[style] ~29-~29: Consider using a different verb for a more formal wording.
Context: ...` policy rule function. ### Fixed - Fixed the issue with formatting schemas conta...

(FIX_RESOLVE)


Line range hint 1-64: Overall, the changelog is well-maintained and relevant.

The changelog effectively documents the changes across multiple versions, including the fix mentioned in the PR objectives. The entries are clear, concise, and provide valuable information about new features, improvements, and bug fixes. The unreleased section directly addresses the issue with base fields not being properly wrapped, which aligns with the PR objectives.

Tools
LanguageTool

[style] ~29-~29: Consider using a different verb for a more formal wording.
Context: ...` policy rule function. ### Fixed - Fixed the issue with formatting schemas conta...

(FIX_RESOLVE)

packages/runtime/src/enhancements/node/delegate.ts (4)

236-236: Method Signature Updated Correctly

The addition of the includeConcreteFields parameter with a default value ensures backward compatibility with existing method calls.


261-263: Conditional Inclusion of Concrete Fields Implemented Properly

The conditional check for includeConcreteFields before invoking injectConcreteIncludeRecursively appropriately controls the inclusion of concrete fields based on the parameter's value.


349-350: Properly Generating Include Payload for Sub-Model Relations

The introduction of createConcreteRelationIncludePayload enhances the clarity and modularity of the code by separating the creation of the include payload for sub-model relations.


372-372: Verify Recursive Call Does Not Introduce Side Effects

Calling buildSelectIncludeHierarchy recursively with includeConcreteFields set to false could potentially skip necessary concrete fields in certain cases. Verify that all required fields are included in the final hierarchy, and the recursive call behaves as expected without unintended omissions.

Run the following script to check for any missing fields in the hierarchy:

Verification successful

✅ Verified: Recursive Call Does Not Introduce Side Effects

No instances of buildSelectIncludeHierarchy are called with includeConcreteFields set to false. All necessary concrete fields are included in the final hierarchy as expected.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all necessary fields are included in the hierarchy.

# Test: Search for calls to buildSelectIncludeHierarchy with includeConcreteFields set to false.
# Expect: Ensure that this does not cause any required fields to be omitted.

rg --type ts --fixed-strings 'await this.buildSelectIncludeHierarchy' -A 3 | grep 'includeConcreteFields: false'

Length of output: 114


Script:

#!/bin/bash
# Description: Retrieve all calls to buildSelectIncludeHierarchy and inspect the includeConcreteFields argument.

# Use ast-grep to find all call expressions of buildSelectIncludeHierarchy and print the third argument.
ast-grep --lang typescript --pattern 'await this.buildSelectIncludeHierarchy($_, $_, $_)' --print-pattern | grep 'false'

Length of output: 341


Script:

#!/bin/bash
# Description: Retrieve all calls to buildSelectIncludeHierarchy and inspect the includeConcreteFields argument.

# Use ripgrep to find all calls to buildSelectIncludeHierarchy and extract the includeConcreteFields parameter.
rg --type ts 'await\s+this\.buildSelectIncludeHierarchy\s*\(([^)]*)\)' -o --only-matching | grep 'includeConcreteFields\s*:\s*false'

Length of output: 134


Script:

#!/bin/bash
# Description: Retrieve all calls to buildSelectIncludeHierarchy and inspect the includeConcreteFields argument.

# Use ripgrep to find all calls to buildSelectIncludeHierarchy and extract the includeConcreteFields parameter if it exists
rg --type ts 'await\s+this\.buildSelectIncludeHierarchy\s*\(([^)]*)\)' -o --only-matching | \
grep -E 'includeConcreteFields\s*:\s*(true|false)' || echo "No buildSelectIncludeHierarchy calls with includeConcreteFields parameter found."

Length of output: 315

tests/regression/tests/issue-1734.test.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant