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(zmodel): fields from base model cannot be accessed from future(). #1704

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 16, 2024

Fixes #1695

Copy link
Contributor

coderabbitai bot commented Sep 16, 2024

Walkthrough

Walkthrough

The pull request modifies the ZModelScopeProvider class to change the method of creating scopes for data models. The previous method, createScopeForNodes, has been replaced with createScopeForModel, indicating a potential shift in how model fields are processed. Additionally, a new regression test has been introduced to validate soft deletion functionality in models, ensuring that access control rules are correctly enforced for deleted records.

Changes

Files Change Summary
packages/schema/src/language-server/zmodel-scope.ts Modified the method for creating a scope in ZModelScopeProvider from createScopeForNodes to createScopeForModel.
tests/regression/tests/issue-1695.test.ts Added a regression test for soft deletion functionality in models, validating access control rules for deleted records.

Assessment against linked issues

Objective Addressed Explanation
Ensure the model's access control rules function correctly with soft deletion (issue #1695)
Resolve the error related to referencing abstract fields in access control rules (issue #1695) The PR does not directly address the error.

Possibly related PRs


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b56d7d and 77829c6.

Files selected for processing (2)
  • packages/schema/src/language-server/zmodel-scope.ts (1 hunks)
  • tests/regression/tests/issue-1695.test.ts (1 hunks)
Additional comments not posted (2)
tests/regression/tests/issue-1695.test.ts (1)

1-21: LGTM!

The regression test is well-structured and follows best practices. The test defines an abstract model for soft deletion and a concrete model that extends it, with appropriate deny rules to enforce soft deletion behavior.

The test should catch regressions related to soft deletion and ensure that access control rules are correctly enforced for deleted records.

packages/schema/src/language-server/zmodel-scope.ts (1)

207-207: Verify the behavior of createScopeForModel.

The change in the createScopeForContainingModel method to use createScopeForModel instead of createScopeForNodes suggests a shift in how the scope is constructed for a containing model. While this change looks good, it's important to ensure that createScopeForModel correctly handles the model and its fields to maintain the expected behavior.

Please verify that createScopeForModel extracts the model's fields correctly and creates a scope that aligns with the previous functionality. This can be done by:

  1. Reviewing the implementation of createScopeForModel to ensure it handles the model and its fields appropriately.
  2. Testing scenarios where the containing model's scope is used, such as resolving references within the model, to confirm the expected behavior is maintained.
Verification successful

Verification successful: createScopeForModel maintains expected behavior

The implementation of createScopeForModel correctly handles the model and its fields. It uses getModelFieldsWithBases(node) to extract the model's fields and creates a scope from them using createScopeForNodes. The change in createScopeForContainingModel to use createScopeForModel instead of directly calling createScopeForNodes maintains the expected behavior while potentially improving code organization.

The usage of both methods throughout the file suggests that this change is consistent with the overall scope creation strategy in the codebase. The new implementation should continue to work correctly in scenarios where the containing model's scope is needed, such as resolving references within the model.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of `createScopeForModel`.

# Test 1: Search for the implementation of `createScopeForModel`. 
# Expect: The method should correctly extract the model's fields and create a scope from them.
ast-grep --lang typescript --pattern $'createScopeForModel(node, globalScope) {
  $$$
}'

# Test 2: Search for usage of `createScopeForContainingModel`. 
# Expect: The method should be used in scenarios where the containing model's scope is needed.
rg --type typescript -A 5 $'createScopeForContainingModel'

Length of output: 653


Script:

#!/bin/bash
# Description: Verify the behavior of createScopeForModel and related methods

# Search for the implementation of createScopeForModel
echo "Searching for createScopeForModel implementation:"
rg -n "createScopeForModel\s*\(" -A 10

# Search for the implementation of createScopeForContainingModel
echo "Searching for createScopeForContainingModel implementation:"
rg -n "createScopeForContainingModel\s*\(" -A 10

# Search for usage of createScopeForContainingModel
echo "Searching for createScopeForContainingModel usage:"
rg -n "createScopeForContainingModel\s*\("

# Search for usage of createScopeForModel
echo "Searching for createScopeForModel usage:"
rg -n "createScopeForModel\s*\("

Length of output: 11816


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 generate interesting stats about this repository and render them as a table.
    -- @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.

@ymc9 ymc9 merged commit 1395892 into dev Sep 16, 2024
13 checks passed
@ymc9 ymc9 deleted the fix/issue-1695 branch September 16, 2024 17:02
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