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

Access policy cause the Prisma runtime validation error #704

Closed
jiashengguo opened this issue Sep 20, 2023 · 3 comments
Closed

Access policy cause the Prisma runtime validation error #704

jiashengguo opened this issue Sep 20, 2023 · 3 comments
Milestone

Comments

@jiashengguo
Copy link
Member

jiashengguo commented Sep 20, 2023

Use the below zmodel schema file:
https://github.com/noufalr/open/blob/main/schema.zmodel

running the below code:

    const client = enhance(prisma, { user: { id: 1 } };
    const myCorseIds = [randomUUID()];
    const result = await client.enrollment.count({
        where: {
            course_id: {
                in: myCorseIds,
            },
        },
    });

It shows the error in my machine:

Argument `id`: Invalid value provided. Expected StringFilter or String, provided Int.
    at /Users/jiasheng/branch/my-try-prisma/src/zen.ts:10:44,
    at step (/Users/jiasheng/branch/my-try-prisma/src/zen.ts:33:23),
    at Object.next (/Users/jiasheng/branch/my-try-prisma/src/zen.ts:14:53),
    at /Users/jiasheng/branch/my-try-prisma/src/zen.ts:8:71,
    at new Promise (<anonymous>),
    at __awaiter (/Users/jiasheng/branch/my-try-prisma/src/zen.ts:4:12),
    at bookSeat (/Users/jiasheng/branch/my-try-prisma/src/zen.ts:44:12),
    at /Users/jiasheng/branch/my-try-prisma/src/zen.ts:22:11,
    at step (/Users/jiasheng/branch/my-try-prisma/src/zen.ts:33:23) {
  name: 'PrismaClientValidationError',
  clientVersion: '5.2.0',

But according to the customer, the error is:

Unknown argument `is`. Available options are listed in green.
    at load (D:/Dev/Repos/lmsapp/src/routes/(app)/courses/+page.server.ts:40:57),
    at async Module.load_server_data (D:/Dev/Repos/lmsapp/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:57:17),
    at async eval (D:/Dev/Repos/lmsapp/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:150:13) {
  name: 'PrismaClientValidationError',
  clientVersion: '5.3.1',
@ymc9
Copy link
Member

ymc9 commented Sep 20, 2023

Two problems here:

  1. The context user passed to enhance has mismatching id field typing. This should be validated against User model.
  2. After fixing the id typing, you can see the real error. The problem is with rules like authors == auth(), which should actually be authors?[this == auth(). CLI hasn't caught such typing error.

@ymc9
Copy link
Member

ymc9 commented Oct 3, 2023

The CLI now captures the errors in comparing things like authors == auth(). I'm keeping this issue open for tracking how to validate typing of the user context.

@ymc9 ymc9 added this to the v2.0.0 milestone Dec 9, 2023
@ymc9
Copy link
Member

ymc9 commented Mar 24, 2024

The user context now has strong typing. Closing.

@ymc9 ymc9 closed this as completed Mar 24, 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