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

[BUG] Query Discrepancy with Selected Relation Fields #1427

Closed
azoom-dang-van-hoi opened this issue May 9, 2024 · 2 comments
Closed

[BUG] Query Discrepancy with Selected Relation Fields #1427

azoom-dang-van-hoi opened this issue May 9, 2024 · 2 comments
Milestone

Comments

@azoom-dang-van-hoi
Copy link

azoom-dang-van-hoi commented May 9, 2024

Description and expected behavior
When querying data with ZenStack and selecting fields with a value of false or undefined within relation models, ZenStack includes these fields in the query results, contrary to the expected behavior observed with Prisma. Prisma correctly excludes fields with these values from the returned data.

// Query with ZenStack (incorrect behavior)
const data = await enhanced.user.findFirst({
  select: {
    id: true,
    name: true,
    profile: false // This field should not be included in the result
  }
})

// Actual Result 
{
  id: 1,
  name: 'John Doe',
  profile: {
      id: 1,
  }
}

// Expected result (observed with Prisma)
{
  id: 1,
  name: 'John Doe'
}

Environment:

  • ZenStack version: 1.6.0
  • Prisma version: 5.4.2
  • Database type: Mysql

Additional context
The bug was identified within the code responsible for the injectForRead check. The automatic addition of the where clause to the field causes the extra data to be retrieved during the get operation.
I suggest filtering out fields with values of false or undefined in the select option before executing the query.

@azoom-dang-van-hoi azoom-dang-van-hoi changed the title Query Discrepancy with Selected Fields Query Discrepancy with Selected Fields and InjectForRead Behavior in Relation Models May 9, 2024
@azoom-dang-van-hoi azoom-dang-van-hoi changed the title Query Discrepancy with Selected Fields and InjectForRead Behavior in Relation Models [Bug] Query Discrepancy with Selected Fields and InjectForRead Behavior in Relation Models May 9, 2024
@azoom-dang-van-hoi azoom-dang-van-hoi changed the title [Bug] Query Discrepancy with Selected Fields and InjectForRead Behavior in Relation Models [BUG] Query Discrepancy with Selected Fields and InjectForRead Behavior in Relation Models May 9, 2024
@azoom-dang-van-hoi azoom-dang-van-hoi changed the title [BUG] Query Discrepancy with Selected Fields and InjectForRead Behavior in Relation Models [BUG] Query Discrepancy with Selected Relation Fields May 9, 2024
@ymc9
Copy link
Member

ymc9 commented May 10, 2024

Thanks for reporting this @azoom-dang-van-hoi ! Yes, there seems to be a problem when handling relation fields. I'll make a fix and include it in the upcoming 2.1.0 release.

@ymc9
Copy link
Member

ymc9 commented May 13, 2024

Fixed in 2.1.0

@ymc9 ymc9 closed this as completed May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants