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

Args are out of sync with the action type for count when creating prisma middeware #15644

Closed
joe-giunti-kiefa opened this issue Oct 3, 2022 · 4 comments · Fixed by #15897
Closed
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: middleware
Milestone

Comments

@joe-giunti-kiefa
Copy link

joe-giunti-kiefa commented Oct 3, 2022

The arguments in a prisma middleware function are out of sync with the type of the action. If you try to reconstruct the prisma action from the args and action that are in the MiddlewareParams it does not work for count.

let prisma: PrismaClient

//this creates an invalid query because the args in param.args are not valid for params.action=count
//it produces this instead {"args":{"select":{"_count":{"select":{"_count":{"select":{"_all":true}}}}}},"dataPath":[],"runInTransaction":true,"action":"count","model":"User"}
const prismaAction = prisma[modelName][params.action](params.args);

const [, results] = await prisma.$transaction([
  prisma.$executeRawUnsafe(`SET LOCAL request.orgId = '${org}'`),
  prismaAction
]);

The only workaround is to set override this back to aggregate

if (params.action == "count") params.action="aggregate"
//this works now
const prismaAction = prisma[modelName][params.action](params.args);

const [, results] = await prisma.$transaction([
  prisma.$executeRawUnsafe(`SET LOCAL request.orgId = '${org}'`),
  prismaAction
]);
@joe-giunti-kiefa
Copy link
Author

It is related to this issue

@joe-giunti-kiefa
Copy link
Author

@millsp Here is the issue you requested

@joe-giunti-kiefa joe-giunti-kiefa changed the title Args are out of sync with the action type when creating prisma middeware Args are out of sync with the action type for count when creating prisma middeware Oct 3, 2022
@millsp
Copy link
Member

millsp commented Oct 3, 2022

Thank you very much @joe-giunti-kiefa !

@millsp millsp added team/client Issue for team Client. kind/bug A reported bug. bug/2-confirmed Bug has been reproduced and confirmed. topic: middleware labels Oct 4, 2022
@millsp
Copy link
Member

millsp commented Oct 19, 2022

Test/reproduction at #15893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: middleware
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants