prisma-client-go
prisma-client-go copied to clipboard
Running an update after FindMany fails with a FieldNotFoundError when FindMany gives back an empty result
Running an update after FindMany fails with a FieldNotFoundError when FindMany gives back an empty result, BUT only when I want to update a foreign key field.
Error in query graph construction: QueryParserError(ObjectValidationError { object_name: "Mutation", inner: FieldValidationError { field_name: "updateManyNetwork", inner: ArgumentValidationError { argument: "data", inner: ObjectValidationError { object_name: "NetworkUpdateManyMutationInput", inner: FieldValidationError { field_name: "owner", inner: FieldNotFoundError } } } } })
example:
_, err := r.Client.Network.FindMany(
db.Network.ID.Equals("ckfxy9dh00003c5rp97l1cica"),
db.Network.UpdatedAt.Before(timestamp),
).Update(
db.Network.Owner.Link(db.User.ID.Equals("ckfxy02u30002c5rpvlxchzx8")), // foreign key field; update fails
db.Network.OwnerID.Set("ckfxy02u30002c5rpvlxchzx8"), // tried this alternatively; same error
db.Network.Name.Set("some name"), // normal field; no problem when findMany does not find anything.
).Exec(ctx)
relevant part of the model:
model Network {
id String @id @default(cuid())
owner User @relation(fields: [ownerId], references: [id])
ownerId String
name String
}
Did you make sure to go run github.com/prisma/prisma-client-go
again? If yes, can you please set export DEBUG=*
and export PHOTON_GO_LOG=info
and share the logs here (or at [email protected])?
It looks like the Prisma query engine doesn't allow setting foreign keys (linking records) in FindMany, while it is possible in FindOne. I'll investigate further and will report back.
For a temporary solution, you might be able to use FindOne if it's possible to exclude the UpdatedAt
query with your use case.
It's indeed something the query engine doesn't support at this time. I've created an issue at prisma/prisma.
Thank you!
I have re-opened this as a feature request. For now, it will depend on https://github.com/prisma/prisma/issues/3887.
This now depends on https://github.com/prisma/prisma-client-go/issues/308. When that is done, we need add a constraint to Link/Unlink to not accept this payload. Instead, the user should use unchecked scalar writes.
This would look as follows when taking the original example (note that this doesn't work at this time):
_, err := r.Client.Network.FindMany(
db.Network.ID.Equals("ckfxy9dh00003c5rp97l1cica"),
db.Network.UpdatedAt.Before(timestamp),
).Update(
db.Network.OwnerID.Set("ckfxy02u30002c5rpvlxchzx8"),
db.Network.Name.Set("some name"),
).Exec(ctx)
depends on #401 now