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: incorrect prisma query executed when count using a where filter involving a polymorphic base field #1586

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Jul 14, 2024

Fixes #1585

Copy link
Contributor

coderabbitai bot commented Jul 14, 2024

Walkthrough

Walkthrough

The changes refactor the buildWhereHierarchy method into injectWhereHierarchy to recursively manage field hierarchies in DelegateProxyHandler. Integration and regression tests were added to validate compound and nested filters, and an edge case related to issue 1585.

Changes

Files/Modules Change Summary
packages/runtime/src/enhancements/delegate.ts Refactored buildWhereHierarchy method to injectWhereHierarchy for improved recursive hierarchy handling.
tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts Added tests for compound and nested filters, ordering by base fields, and counting with specific conditions.
tests/regression/tests/issue-1585.test.ts Introduced regression test case for issue 1585, including schema loading, model creation, and specific count assertions.

Assessment against linked issues

Objective Addressed Explanation
Incorrect prisma query executed when count using a where filter involving a polymorphic base field (#1585)
Added regression tests to validate compound and nested filters (#1585)

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 show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a11ab8c and d626b07.

Files selected for processing (3)
  • packages/runtime/src/enhancements/delegate.ts (10 hunks)
  • tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts (2 hunks)
  • tests/regression/tests/issue-1585.test.ts (1 hunks)
Additional comments not posted (17)
tests/regression/tests/issue-1585.test.ts (6)

1-1: Import statement looks good.

The import statement correctly imports the loadSchema function from @zenstackhq/testtools.


2-2: Describe block is well-defined.

The describe block correctly names the test suite as 'issue 1585'.


3-3: It block is well-defined.

The it block correctly names the test case as 'regression'.


4-19: Schema definition is correct.

The schema definition includes the Asset and Post models, with the Post model extending the Asset model. The Asset model includes the necessary fields and annotations.


21-23: Database operations are correct.

The database operations correctly create two Post entries with different views values.


24-28: Assertion is correct.

The assertion correctly checks that the count of posts with views greater than 0 is 1.

packages/runtime/src/enhancements/delegate.ts (7)

98-99: Initial checks in injectWhereHierarchy method are correct.

The initial checks correctly ensure that the where parameter is a plain object.


Line range hint 100-104: Logical group handling in injectWhereHierarchy method is correct.

The method correctly handles logical groups (AND, OR, NOT) by recursively calling injectWhereHierarchy.


Line range hint 105-112: Field information resolution in injectWhereHierarchy method is correct.

The method correctly resolves field information and handles fields that are data models by recursively calling injectWhereHierarchy.


Line range hint 113-134: Base model handling in injectWhereHierarchy method is correct.

The method correctly handles base models by preparing the base layer where clause and injecting the field value.


890-890: aggregate method correctly uses injectWhereHierarchy.

The aggregate method correctly uses injectWhereHierarchy for the cursor, orderBy, and where parameters.


894-894: count method correctly uses injectWhereHierarchy.

The count method correctly uses injectWhereHierarchy for the cursor and where parameters.


958-958: groupBy method correctly uses injectWhereHierarchy.

The groupBy method correctly uses injectWhereHierarchy for the where parameter.

tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts (4)

287-313: LGTM! Verify the correctness of compound filter handling.

The new test for reading with compound filters is well-structured and covers various scenarios. Ensure that the compound filter handling is correct and consistent across the codebase.

Verification successful

Verified: Compound filter handling is correctly implemented in the new test.

The new test for reading with compound filters is well-structured and covers various scenarios. The compound filters AND, OR, and NOT are correctly used and verified within the test.

  • tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of compound filter handling.

# Test: Search for the usage of compound filters in the codebase.
rg --type typescript -A 5 $'findMany({ where: { AND:'

Length of output: 163


Script:

#!/bin/bash
# Description: Verify the correctness of compound filter handling.

# Test: Search for the usage of compound filters in the codebase.
rg --type typescript -A 5 'findMany\(\{ where: \{ AND:'

Length of output: 92


Script:

#!/bin/bash
# Description: Verify the correctness of compound filter handling.

# Test: Search for the usage of compound filters in the codebase.
rg --type ts -A 5 'findMany\(\{ where: \{ AND:'
rg --type ts -A 5 'findMany\(\{ where: \{ OR:'
rg --type ts -A 5 'findMany\(\{ where: \{ NOT:'

Length of output: 2627


Line range hint 350-366:
LGTM! Verify the correctness of ordering by base fields handling.

The new test for ordering by base fields is well-structured and covers various scenarios. Ensure that the ordering by base fields handling is correct and consistent across the codebase.


1080-1091: LGTM! Verify the correctness of count handling with specific conditions.

The new test for counting with specific conditions is well-structured and covers various scenarios. Ensure that the count handling with specific conditions is correct and consistent across the codebase.

Verification successful

Verified: The count method handles specific conditions correctly.

The instances of the count method usage across the codebase confirm that the method handles various conditions consistently and correctly. The tests cover both successful and expected-to-fail scenarios, ensuring robust validation.

  • tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts: Verified instances of count with specific conditions.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of count handling with specific conditions.

# Test: Search for the usage of count with specific conditions in the codebase.
rg --type typescript -A 5 $'count({ select:'

Length of output: 142


Script:

#!/bin/bash
# Description: Verify the correctness of count handling with specific conditions.

# Test: Search for the usage of count with specific conditions in the codebase.
rg --type typescript -A 5 'count\(\{ select:'

Length of output: 82


Script:

#!/bin/bash
# Description: Verify the correctness of count handling with specific conditions.

# Find all TypeScript files and search for the usage of count with specific conditions in those files.
fd -e ts -x rg 'count\(\{ select:' -A 5

Length of output: 259


Script:

#!/bin/bash
# Description: Verify the correctness of count handling with specific conditions.

# Find all TypeScript files and search for the usage of count with specific conditions in those files.
fd -e ts -x rg 'count\(' -A 10

Length of output: 11433


315-349: LGTM! Verify the correctness of nested filter handling.

The new test for reading with nested filters is well-structured and covers the scenario. Ensure that the nested filter handling is correct and consistent across the codebase.

@ymc9 ymc9 merged commit 3140d9b into dev Jul 14, 2024
13 checks passed
@ymc9 ymc9 deleted the fix/issue-1585 branch July 14, 2024 06:33
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