Skip to content

policy errors with polymorphic models #1770

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

Closed
j0rdanba1n opened this issue Oct 10, 2024 · 10 comments
Closed

policy errors with polymorphic models #1770

j0rdanba1n opened this issue Oct 10, 2024 · 10 comments
Milestone

Comments

@j0rdanba1n
Copy link
Contributor

j0rdanba1n commented Oct 10, 2024

My zmodels are:

abstract model BaseAuth {
    id             String        @id @default(uuid())
    dateCreated    DateTime      @default(now())
    dateUpdated    DateTime      @updatedAt @default(now())

    organizationId String?
    organization   Organization? @relation(fields: [organizationId], references: [id], name: "organization")

    @@allow('all', organization.users?[user == auth()])
}

enum ResourceType {
    Personnel
}

model Resource extends BaseAuth {
    name     String?
    type     ResourceType?
    costRate Int?

    budgets  ResourceBudget[]

    @@delegate(type)
}

model Personnel extends Resource {
}

I get this error when trying to query a resource:

Invalid `prisma.resource.findMany()` invocation:

{
  where: {
    OR: [
      {
        OR: [
          {
            organization: {
              users: {
                some: {
                  user: {
                    is: {
                      id: "553a6c87-3a77-475b-8f56-f5fb59f92630"
                    }
                  }
                }
              }
            }
          }
        ]
      }
    ]
  },
  include: {
    delegate_aux_personnel: {
      where: {
        OR: [
          {
            OR: [
              {
                organization: {
                  users: {
                    some: {
                      user: {
                        is: {
                          id: "553a6c87-3a77-475b-8f56-f5fb59f92630"
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
      },
      include: {
        delegate_aux_resource: {}
      }
    }
  }
}

Unknown argument `organization`. Available options are marked with ?.

Originally posted by @j0rdanba1n in #1734 (comment)

@j0rdanba1n j0rdanba1n changed the title policy errors with polymorphic (delegate) models policy errors with polymorphic models Oct 10, 2024
@j0rdanba1n
Copy link
Contributor Author

@ymc9 - happy to help fix this if it's a bug - I might just need some pointers

@ymc9
Copy link
Member

ymc9 commented Oct 11, 2024

Thanks for filing this @j0rdanba1n . Is this with the latest version? I'll check it and update back here.

@j0rdanba1n
Copy link
Contributor Author

Yes - it is with latest version :)

@j0rdanba1n
Copy link
Contributor Author

@ymc9 do you have any idea what the problem is? This is currently blocking me. Thank you :)

@ymc9 ymc9 added this to the v2.7.0 milestone Oct 14, 2024
@ymc9
Copy link
Member

ymc9 commented Oct 14, 2024

abstract model BaseAuth {
id String @id @default(uuid())
dateCreated DateTime @default(now())
dateUpdated DateTime @updatedAt @default(now())

organizationId String?
organization   Organization? @relation(fields: [organizationId], references: [id], name: "organization")

@@allow('all', organization.users?[user == auth()])

}

enum ResourceType {
Personnel
}

model Resource extends BaseAuth {
name String?
type ResourceType?
costRate Int?

budgets  ResourceBudget[]

@@delegate(type)

}

model Personnel extends Resource {
}

Hey, I can reproduce the issue now. Will try to make a fix in the upcoming v2.7 release.

@j0rdanba1n
Copy link
Contributor Author

omg! thank you for such a quick fix <3 when do you expect to release v2.7.0?

@ymc9
Copy link
Member

ymc9 commented Oct 15, 2024

omg! thank you for such a quick fix <3 when do you expect to release v2.7.0?

Trying my best to wrap it up now 😄. It should land no later than end of tomorrow.

@ymc9 ymc9 closed this as completed Oct 17, 2024
@eqqe
Copy link

eqqe commented Oct 17, 2024

Hello, I also have a problem when adding an index on model Resource

@@index([organizationId])

Does not compile for prisma because it copies the index to the delegated model

@ymc9
Copy link
Member

ymc9 commented Oct 17, 2024

Hi @eqqe , could you help create a new issue for it? I'd like to fix it soon and release a patch.

@eqqe
Copy link

eqqe commented Oct 17, 2024

#1786

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

3 participants