Ortharion
Ortharion
PPrisma
Created by Ortharion on 9/11/2024 in #help-and-questions
Bad error messages with array of transactions
Sure. Thanks
9 replies
PPrisma
Created by Ortharion on 9/11/2024 in #help-and-questions
Bad error messages with array of transactions
I'm pretty sure this is a bug report and not a request for help. But I wanted to make sure I didn't miss something in the docs somewhere about how to properly manage errors when using an array of prisma promises in a $transaction
9 replies
PPrisma
Created by Ortharion on 9/11/2024 in #help-and-questions
Bad error messages with array of transactions
And the schema isn't super important here. I intentionally put a bad property to force the error. Getting an error isn't the issue, it's when we have errors, prisma is NOT bubbling the correct information.
9 replies
PPrisma
Created by Ortharion on 9/11/2024 in #help-and-questions
Bad error messages with array of transactions
Apologies, I thought I was doing that approach? Oh I didn't put the actual line of the transaction.
//this is what the concatenated transactions would look like after all the //condition checks from the original code snippet. This is just for brevity.
//This code works in production and this is just to isolate the example of an //error state not bubbling up properly
const transactions = [
this.prismaClient.systems.upsert(query),
this.prismaClient.equipmentPhotos.upsert(query)
]


const result = await this.prismaClient.$transaction(transactions);
//this is what the concatenated transactions would look like after all the //condition checks from the original code snippet. This is just for brevity.
//This code works in production and this is just to isolate the example of an //error state not bubbling up properly
const transactions = [
this.prismaClient.systems.upsert(query),
this.prismaClient.equipmentPhotos.upsert(query)
]


const result = await this.prismaClient.$transaction(transactions);
9 replies
PPrisma
Created by Ortharion on 9/11/2024 in #help-and-questions
Bad error messages with array of transactions
Actual prisma error
"message": "\nInvalid `prisma.systems.upsert()` invocation:\n\n{\n where: {\n id: \"0e306bfd-19d4-4a5d-a236-8b6b0b6eb5e6\"\n },\n create: {\n id: \"7de075b7-179f-4762-a615-619e10b6214a\",\n updated_by: \"b9ad90e0-17fc-4e22-b715-a62073f6b42a\",\n updated_at: 1726098171191,\n deleted_at: 1726098171191,\n? parent?: String | Null,\n? regularImageName?: String | Null,\n? infraredImageName?: String | Null,\n? description?: String | Null,\n? system?: String | Null,\n? uploaded?: Boolean | Null,\n? simulation?: String | Null,\n? category?: String | Null,\n? originalEquipmentId?: String | Null,\n? latitude?: Int | Null,\n? longitude?: Int | Null,\n? altitude?: Int | Null,\n? heading?: Int | Null,\n? locationAccuracy?: Int | Null,\n? altitudeAccuracy?: Int | Null,\n? detectedInfo?: NullableJsonNullValueInput | Json,\n? created_at?: BigInt | Null,\n? created_by?: String | Null\n },\n update: {\n updated_by: \"b9ad90e0-17fc-4e22-b715-a62073f6b42a\",\n updated_at: 1726098171191,\n deleted_at: 1726098171191\n }\n}\n\nUnknown argument `unknownProperty`. Available options are marked with ?."
"message": "\nInvalid `prisma.systems.upsert()` invocation:\n\n{\n where: {\n id: \"0e306bfd-19d4-4a5d-a236-8b6b0b6eb5e6\"\n },\n create: {\n id: \"7de075b7-179f-4762-a615-619e10b6214a\",\n updated_by: \"b9ad90e0-17fc-4e22-b715-a62073f6b42a\",\n updated_at: 1726098171191,\n deleted_at: 1726098171191,\n? parent?: String | Null,\n? regularImageName?: String | Null,\n? infraredImageName?: String | Null,\n? description?: String | Null,\n? system?: String | Null,\n? uploaded?: Boolean | Null,\n? simulation?: String | Null,\n? category?: String | Null,\n? originalEquipmentId?: String | Null,\n? latitude?: Int | Null,\n? longitude?: Int | Null,\n? altitude?: Int | Null,\n? heading?: Int | Null,\n? locationAccuracy?: Int | Null,\n? altitudeAccuracy?: Int | Null,\n? detectedInfo?: NullableJsonNullValueInput | Json,\n? created_at?: BigInt | Null,\n? created_by?: String | Null\n },\n update: {\n updated_by: \"b9ad90e0-17fc-4e22-b715-a62073f6b42a\",\n updated_at: 1726098171191,\n deleted_at: 1726098171191\n }\n}\n\nUnknown argument `unknownProperty`. Available options are marked with ?."
9 replies
PPrisma
Created by Ortharion on 8/15/2024 in #help-and-questions
Invalid error message when using transactions
bump
5 replies
PPrisma
Created by Ortharion on 8/15/2024 in #help-and-questions
Invalid error message when using transactions
And this is kind of frustrating b/c obviously when this endpoint has issues, it's a big deal b/c our mobile app users are no longer able to push data to the database. So being able to quickly isolate the issue is important.
5 replies
PPrisma
Created by Ortharion on 4/25/2024 in #help-and-questions
Transaction timeout
Yep, that fixed...but why lol
7 replies
PPrisma
Created by Ortharion on 4/25/2024 in #help-and-questions
Transaction timeout
ok i think I might have figured it out. I wrote that endpoint a while back and forgot I had some transactions nested in some of the functions in addUser. So I think transactions within transactions is illegal. However, why does this work on local?
7 replies
PPrisma
Created by Ortharion on 4/25/2024 in #help-and-questions
Transaction timeout
Transaction API error: Transaction already closed: A commit cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 5069 ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the transaction
Transaction API error: Transaction already closed: A commit cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 5069 ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the transaction
Sorry should have added that. Think I was just frustrated after being stumped all day. I've checked and this only fires once.
const createdUser = await prismaClient.$transaction(async (prisma: PrismaClient) => {

const userService = new UserService(prisma);
const companyService = new CompanyService(prisma);
const { user: callingUser } = await userService.getUserUsingToken(sessionData.token!);

const user = {
email: body.email,
addedBy: callingUser?.id,
companyId: companyId,
firstName: body.firstName,
lastName: body.lastName,
isAdmin: body.isAdmin,
isBillable: body.isBillable ?? true,
isActive: body.isActive ?? true,
departmentId: body.departmentId,
} as Partial<Users>;

return await companyService.addUser(user, companyId);

})

return NextResponse.json({ success: true, user: createdUser });
const createdUser = await prismaClient.$transaction(async (prisma: PrismaClient) => {

const userService = new UserService(prisma);
const companyService = new CompanyService(prisma);
const { user: callingUser } = await userService.getUserUsingToken(sessionData.token!);

const user = {
email: body.email,
addedBy: callingUser?.id,
companyId: companyId,
firstName: body.firstName,
lastName: body.lastName,
isAdmin: body.isAdmin,
isBillable: body.isBillable ?? true,
isActive: body.isActive ?? true,
departmentId: body.departmentId,
} as Partial<Users>;

return await companyService.addUser(user, companyId);

})

return NextResponse.json({ success: true, user: createdUser });
7 replies