result
extension that shadows a field of the same name causes Maximum call stack exceeded
at runtime
#16643
Labels
bug/2-confirmed
Bug has been reproduced and confirmed.
kind/bug
A reported bug.
team/client
Issue for team Client.
tech/typescript
Issue for tech TypeScript.
topic: clientExtensions
Milestone
Bug description
When a
result
extension adds a computed field that shadows a field of the same name, AND the extension fieldneeds
the shadowed field, the following error occurs:Here is where the issue actually happens:
https://github.com/prisma/prisma/blob/main/packages/client/src/runtime/core/extensions/resultUtils.ts#L58
(
resolveNeeds
doesn't check for cycles in the dependencies)How to reproduce
Repository with a minimal reproduction and instructions in the README: https://github.com/sbking/prisma-client-extensions-shadowing
Expected behavior
A computed field should be able to shadow a field of the same name, and use the original value to compute the computed value.
This works at the type level - the extended client uses the data type returned by the computed field, not the type of the original field.
The TypeScript types also seem suggest that you can chain extensions that shadow the same computed field. This would be intuitive, but the docs suggest that the last extension always wins in the case of conflicts. See the inferred inlay hints in this screenshot:
Prisma information
Here is the extension code:
And here is where the error occurs:
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: