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

Unselected Fields Returning as null When Using select in Prisma Dart #436

Open
Hackman-Adu opened this issue Oct 12, 2024 · 2 comments
Open
Labels
dart Pull requests that update Dart code feature platform:dart type:client

Comments

@Hackman-Adu
Copy link

What version of Prisma Dart is running?

5.2.0

What version of Prisma CLI is running?

5.20.0

What type of app are you using?

Dart Native (Server/CLI)

What database are you using?

MySQL

What steps can reproduce the bug?

var user = await prisma.user.findUnique(
  select: UserSelect(
    firstName: true, lastName: true, password: true, userId: true),
  where: UserWhereUniqueInput(emailAddress: '[email protected]')
);

What is the expected behavior?

Only the selected fields (firstName, lastName, password, userId) should be returned.

What do you see instead?

Other unselected fields are also returned with null values.

Additional information

I encountered an issue where unselected fields are being returned as null in the response when using the select option with Prisma Dart. I expected Prisma to only return the fields I selected, but instead, it returns other fields as null.

@Hackman-Adu Hackman-Adu added bug Something isn't working needs triage labels Oct 12, 2024
@medz medz added platform:dart type:client feature dart Pull requests that update Dart code and removed bug Something isn't working needs triage labels Oct 12, 2024
@medz
Copy link
Owner

medz commented Oct 12, 2024

@Hackman-Adu Thanks for your feedback, but the requirement you reported cannot be implemented. (Maybe it will be implemented in the future when the macro is officially launched)

But for now, Dart does not distinguish between null input and no input. In Dart, they are all null types. We cannot dynamically construct the return type through select or include.

You should notice that in model.dart, all model classes are nullable fields.

I will keep this issue open and mark it as implementable when Dart supports it or we find other ways to support this behavior.

@Hackman-Adu
Copy link
Author

Hackman-Adu commented Oct 12, 2024

@medz Thanks for the prompt response. Yes, I realized that the unavailability of Dart macros could be the reason behind this limitation. I just wanted to bring it to your attention.

Currently, as a workaround, I am using an extension on maps to handle and filter out null values when select is applied. I appreciate your consideration of this issue and look forward to future updates. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dart Pull requests that update Dart code feature platform:dart type:client
Projects
None yet
Development

No branches or pull requests

2 participants