P
Prisma•3w ago
Crawl

.update return null when data is found using .findUnique using the same where clause (version 5.17.

How is this even possible ? my updatedUser is null, and no updated has been performed But the data exist since the user is found successfully no error is thrown by prisma just updatedUser being null with console loggin User not found or update failed transactionId
const userFound = await this.db.users.findUnique({
where: {
something: xxx,
userId,
},
});

if (!userFound) {
this.logger.log(
`userFound not found`,
);
return null;
}

this.logger.debug('User found');

const updatedUser = await this.db.users.update({
where: {
something: xxx,
userId,
},
data: {
name,
alias,
},
});

if (!updatedUser) {
this.logger.log(
`User not found or update failed transactionId`,
);
return null;
}
const userFound = await this.db.users.findUnique({
where: {
something: xxx,
userId,
},
});

if (!userFound) {
this.logger.log(
`userFound not found`,
);
return null;
}

this.logger.debug('User found');

const updatedUser = await this.db.users.update({
where: {
something: xxx,
userId,
},
data: {
name,
alias,
},
});

if (!updatedUser) {
this.logger.log(
`User not found or update failed transactionId`,
);
return null;
}
3 Replies
Crawl
Crawl•3w ago
@🔨 Moderator @aqrln @Jon Harrell Would love to get your thoughts on this puzzle Been using prisma for 2 years now, and first time not being able to understand this issue
la flame
la flame•3w ago
I had the same issue before. Solved using AND operator in both queries. BTW, set export DEBUG="*" and you could see query differences by yourself.
Crawl
Crawl•2w ago
I ended up finding the issue Basically our schema was not applied correctly because we were using raw queries (create) in one tiny area in the code base causing thoses records to not complie at all with the prisma schema, even if we used the same data type etc.. For prisma they dont exist even thought they are here So my recommendation would be to avoid using raw query for input data at all cost
Want results from more Discord servers?
Add your server