-
-
Notifications
You must be signed in to change notification settings - Fork 106
on v2.6.0 some fields on concrete model inherited from polymorphic base model disappear #1734
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
Comments
Hi! A similar issue happend with me. If a concrete model field access policy has a relation condition, Prisma throws an error:
I created a regression test that reproduces the issue: import { loadSchema } from '@zenstackhq/testtools';
describe('issue new', () => {
it('regression', async () => {
const { enhance, enhanceRaw, prisma } = await loadSchema(
`
abstract model Base {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Profile extends Base {
displayName String
type String
@@allow('read', true)
@@delegate(type)
}
model User extends Profile {
username String @unique
access Access[]
organization Organization[]
}
model Access extends Base {
user User @relation(fields: [userId], references: [id])
userId String
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
manage Boolean @default(false)
superadmin Boolean @default(false)
@@unique([userId,organizationId])
}
model Organization extends Profile {
owner User @relation(fields: [ownerId], references: [id])
ownerId String @default(auth().id)
published Boolean @default(false) @allow('read', access?[user == auth()]) // <-- this policy is causing the issue
access Access[]
}
`,
{
logPrismaQuery: true,
}
);
const db = enhance();
const rootDb = enhanceRaw(prisma, undefined, {
kinds: ['delegate'],
});
const user = await rootDb.user.create({
data: {
username: 'test',
displayName: 'test',
},
});
const organization = await rootDb.organization.create({
data: {
displayName: 'test',
owner: {
connect: {
id: user.id,
},
},
access: {
create: {
user: {
connect: {
id: user.id,
},
},
manage: true,
superadmin: true,
},
},
},
});
const foundUser = await db.profile.findFirst({
where: {
id: user.id,
},
});
expect(foundUser).toBeTruthy();
});
}); |
Hi @tmax22 , The generated Prisma schema looks correct to me. Have you run into any runtime issue? |
Hi @svetch , I appreciate the test case! Looking into it now. |
… when injected from policies Fixes #1734
@ymc9 The new release resolves the issue on my end. Thanks for the quick fix! |
Awesome. Thanks for the confirmation! |
actually, it make sense, but it does introduce a breaking change(since v2.2.4 introduces the schema with the polymorphic model fields). it means that i need to write my schema like this:
(note: however, it does make some issues. how should i make ClientRequirementsStage inherent both from ProductStage and Base in this case? |
For such usage, the |
actually, after checking, it does not currently pose an issue as long we use zenstack to fetch the data because these 'hidden' fields are really fetched at runtime via the |
I'm encountering a similar issue. My zmodels are:
I get this error when trying to query a
I believe the problem is that the policy |
for example, for the given input zmodel schema:
you would get:
note that
ClientRequirementsStage
is missingcreatedAt
andupdatedAt
. the expected output would be:The text was updated successfully, but these errors were encountered: