Repository navigation
Open
Labels
Milestone
Description
Node.js version: v12.13.0
Prisma2 version: [email protected]
Schema:
generator photon {
provider = "photonjs"
}
datasource db {
provider = "sqlite"
url = "file:{**PATH**}/db.sqlite"
}
model ParentRec { @@map(name: "parent")
id String @default(cuid()) @id
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
code String @unique
children ChildRec[]
}
model ChildRec { @@map(name: "child")
id String @default(cuid()) @id
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
code String @unique
parent ParentRec @map(name: "parent_id")
}
Code:
const {Photon} = require('@prisma/photon');
async function main() {
const photon = new Photon();
await photon.connect();
try {
const created = await photon.parentRecs.create({
data: {
code: 'parent',
children: {
create: {
code: 'child'
}
}
},
include: {
children: true
}
});
console.log(created);
const updated = await photon.parentRecs.update({
where: {
code: 'parent'
},
data: {
children: {
update: {
where: {
code: 'not_found' // rec with this code doesn't exist
},
data: {
code: 'child_upd'
}
}
}
},
include: {
children: true
}
});
console.log(updated);
} catch (err) {
console.error(err);
} finally {
await photon.disconnect();
}
}
main().then(() => {
console.log('Completed!');
});
Error:
Error:
Invalid `photon.()` invocation in /home/vadim/Projects/Temp/index.js:23:49
Reason: Error occurred during query execution:
InterpretationError("Error for binding \'1\': AssertionError(\"Expected a valid parent ID to be present for nested update to-one case.\")")
Reacted by commenda-main and Antoine
Activity
pantharshit00 commentedon Dec 5, 2019
This is expected as the relationship is required. Trying to perform an update on a non-existant record will throw. We need to throw a better here though.
janpio commentedon Dec 5, 2019
(Possible that the error is already better in alpha - please check that @pantharshit00)
pantharshit00 commentedon Dec 6, 2019
Nope, it is throwing the same error in alpha.415

dpetrick commentedon Dec 19, 2019
Throwing the error here is correct. The message is not useful, which is known but unrelated to this issue.
tomhoule commentedon Jan 30, 2020
Status update: there are big changes ongoing in the query engine. I haven't worked on this.
tomhoule commentedon Feb 11, 2020
The query engine refactoring has started landing, so I checked whether this crash is still reproducible, and it is. Working on this now.
tomhoule commentedon Feb 11, 2020
This PR contains a test reproduction using the same schema and queries as above. @mavilein as mentioned on slack, this looks very AUMFIDARR-relevant. The TL;DR is that a parent ID is missing on a nested update, where the parent record is found by unique criteria, and the child record too (they also have PKs but they are not used there)
[-]Photon returns an error on update a nested rec[/-][+]Prisma Client returns an error on update a nested rec[/+]mavilein commentedon Mar 20, 2020
I think this should throw this error actually: https://github.com/prisma/prisma-engines/blob/master/libs/user-facing-errors/src/query_engine.rs#L51
11 remaining items
matthewmueller commentedon Feb 24, 2021
Just double-checked this, still running into an unhelpful error. I feel like the confusing part is the "valid parent ID", it's a valid ID, it's just that this ID doesn't exist.
[-]Prisma Client returns an error on update a nested rec[/-][+]Improve error when updating a non-existent nested record[/+]matthewmueller commentedon Mar 1, 2021
We did a pass over the errors and this one isn't easy to improve. We'll get to it eventually, but not right now.
haggalin commentedon Mar 25, 2022
Tested this with:
Tested some different cases here:
Normal update
Throws P2025 with
meta.cause: 'Record to update not found.'Update with a nested create
Throws P2025 with
meta.cause: "No 'User' record (needed to inline the relation with create on 'Contact' record) was found for a nested create on one-to-one relation 'ContactToUser'."Update with a nested update
Throws P2016 with
meta.details: "Error for binding '1': AssertionError("Expected a valid parent ID to be present for nested update to-one case.")"I guess the expectation here is that in the nested update case the error code should be P2025 and a the error message something similar to the message in the nested create case.
zomars commentedon Apr 1, 2022
Thanks to your comment I was able to debug this @haggalin 🙏🏽
reisblucas commentedon Jul 23, 2022
Same error, but in my case, was unknown the cause, initially I thinked was my field as decimal 0.00. Tested manually with query in MySQL and executed the query again with the field assigned with the value 1 and the same error occurs.
My last option, was try reseting my db and seeding again and solved with the same query used before.
I don't know what is the problem and can't see another form beyond that, hope it helps someone.
reisblucas commentedon Jul 23, 2022
Appending to my comment above, this was the transaction.
gautamsi commentedon Sep 29, 2024
came across this, IMO we should be able to specify if error should be thrown on non existent entity. For example I would like the item marked archived if the parent item is archiving and the nested item exist, if it does not exist there should not be any problem.