-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Prisma Client errors with "TypeError: Cannot create proxy with a non-object as target or handler" when using result client extension with no needs
and count
method
#20499
Comments
Can you please share the actual code that is being executed there? |
Yes, exactly; The code is something as simply as calling that model with count: export async function search(
params: SearchParams
): TypedPaginatedResponse<(User & { onboarding: { id: string } | null })[]> {
const count = await prisma.user.count();
return {
data: [],
pagination: {
count: [].length,
totalCount: count,
},
};
} And the test with it<TestContext>("should search", async () => {
const r = await search(defaultPagination);
expect(r.data.length).toBeGreaterThan(0);
}); |
The previous version I was of Prisma its: Btw; it's only happening on this model, because I run different tests on other models.count() and works fine. This is the User model, if it helps: model User {
id String @id @default(uuid()) @db.Uuid
email String?
name String?
surname String?
avatar String?
externalId String?
ssn String?
loginMethod LoginMethod?
accessControlList String[]
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
deactivatedAt DateTime? @db.Timestamptz(3)
registeredAt DateTime? @db.Timestamptz(3)
status UserStatus?
/// Optional to allow returning null when we send users to the front-end
passwordSalt String?
/// Optional to allow returning null when we send users to the front-end
password String?
entityId String? @db.Uuid
passwordExpired Boolean?
userType UserType @default(ADVISOR_FF)
defaultRole UserRole @default(ADVISOR)
isBlind Boolean?
isElderly Boolean?
hasChildTaxCredit Boolean?
hasDependentCredit Boolean?
middleName String?
birthDate DateTime? @db.Timestamptz(3)
retirementDate DateTime? @db.Timestamptz(3)
retirementAge Int?
numberOfDependents Int?
riskLevel Int?
investmentObjective Int?
countryOfCitizenshipId String?
countryOfResidenceId String?
prefix Prefix?
sufix Sufix?
gender Gender?
maritalStatus MaritalStatus?
marketFeel MarketFeelings?
riskId String? @db.Uuid
currentRisk Risk? @relation("userRisk", fields: [riskId], references: [id])
dependent Boolean?
authenticationMethod AuthenticationMethods?
authenticationSecret String?
addresses UserAddresses[]
documents UserDocuments[]
phones UserPhones[]
portfolios Portfolio[]
advisorOnboardings Onboarding[] @relation("advisorOnboardings")
countryOfResidence Country? @relation("countryOfResidence", fields: [countryOfResidenceId], references: [id])
entity Entity? @relation(fields: [entityId], references: [id], onDelete: Cascade)
countryOfCitizenship Country? @relation("countryOfCitizenship", fields: [countryOfCitizenshipId], references: [id])
holders Holder[]
benchmarks Benchmark[]
modelPortfolios ModelPortfolio[]
strategies Strategy[]
onboarding Onboarding?
activities UserActivity[]
taskUsers UsersOnTasks[]
guestGroupMembers GroupMembers[]
plaidExtraData PlaidExtraData[]
amount Float?
risks Risk[]
simpleIntegrations Json?
integrationStatus IntegrationStatus?
errorCode String?
errorMessage String?
riskProfile RiskProfile[]
metadata Metadata[]
quickViews QuickView[]
factFinderTemplates FactFinderTemplate[]
userFactFinderCampaigns FactFinderCampaign[]
advisorFactFinderCampaigns FactFinderCampaign[] @relation(name: "advisorCampaigns")
rebalancings Rebalancing[]
taskHistories TaskHistory[] @relation("taskHistoryUser")
affectingTaskHistories TaskHistory[] @relation("userAffected")
taskAttachments TaskAttachment[]
taskComments TaskComment[]
tasks Task[]
mailingTemplates MailingTemplates[]
collaboratingFactFinderCampaigns FactFinderCampaignCollaborators[]
userDevices UserDevices[]
assets Asset[]
liabilities Liability[]
expenses Expense[]
factFinderCampaignFeedback FactFinderCampaignFeedback[]
integrations UserIntegration[]
incomes Income[]
insurances Insurance[]
estates Estate[]
liabilityAmortizations LiabilityAmortization[]
userGoals Goal[] @relation("retirementUser")
headGoals Goal[] @relation("retirementAgeHead")
spouseGoals Goal[] @relation("retirementAgeSpouse")
taxDetails TaxDetail[]
@@index([amount])
@@index([name])
@@index([email])
@@index([userType])
} It's big but worked previously fine, so dunno |
The error message also mentions Can you maybe isolate the schema and code into its own, standalone project so you can see if you can reproduce it? Sharing that project with us would be perfect for us to reproduce, understand and hopefully fix. |
I'll try to isolate but it's a large repo so it's a bit complex, but will try for sure. |
Got it guys! const _prisma = getPrismaClient();
const prisma = _prisma.$extends({
result: {
user: {
password: {
needs: {},
compute() {
return "";
},
},
passwordSalt: {
needs: {},
compute() {
return "";
},
}, On 4.5.1 worked without the needs of specifying the field, after specifying the needs: { field: true }, worked like a charm! const prisma = _prisma.$extends({
result: {
user: {
password: {
needs: { password: true },
compute() {
return "";
},
},
passwordSalt: {
needs: { passwordSalt: true },
compute() {
return "";
},
}, Hope this issue it's hopeful for someone that forgot to add that, and the error is not self-descriptive at all -- I know it's complex but hehe |
Reopening, since it is an actual bug in 5.1. Even though there is a workaround for it (thank you for providing it, @semoal ), we need to fix it. |
Problem: after #20438, we were trying to apply result extensions to "sugared" result of `.count` method - plain number. Theoretically, extensions should not apply there at all, but field with no `needs` applies to every result of a corresponding model. And since result extensions use proxies and proxy can not be created over non-objects, the code thrown very undescriptive error instead. Fix #20499
needs
and count
method
* fix(client): Make sure result extensions don't break `.count` Problem: after #20438, we were trying to apply result extensions to "sugared" result of `.count` method - plain number. Theoretically, extensions should not apply there at all, but field with no `needs` applies to every result of a corresponding model. And since result extensions use proxies and proxy can not be created over non-objects, the code thrown very undescriptive error instead. Fix #20499 * Update packages/client/src/runtime/core/extensions/applyAllResultExtensions.ts Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com> --------- Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
* fix(client): Make sure result extensions don't break `.count` Problem: after #20438, we were trying to apply result extensions to "sugared" result of `.count` method - plain number. Theoretically, extensions should not apply there at all, but field with no `needs` applies to every result of a corresponding model. And since result extensions use proxies and proxy can not be created over non-objects, the code thrown very undescriptive error instead. Fix #20499 * Update packages/client/src/runtime/core/extensions/applyAllResultExtensions.ts Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com> --------- Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
Fix released in 5.1.1 |
Bug description
Just upgraded to 5.1.0, and after adjusting the Array shortcut breaking change, I have run the testing suite and this test fails, I'm not quite sure how to debug this.
Any help or question is appreciated and I would love to help.
Our User schema is quite big so it's complicated to share.
I'm using Postgres, Node 18.13.0, Typescript 5.0.4 and a PNPM monorepo if it helps.
How to reproduce
Expected behavior
No response
Prisma information
// Add your schema.prisma
// Add your code using Prisma Client
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: