-
Notifications
You must be signed in to change notification settings - Fork 1.7k
called Option::unwrap()
on a None
value when using the relationJoins preview feature with driver adapters
#22294
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
Comments
I just tried removing |
Option::unwrap()
on a None
valueOption::unwrap()
on a None
value when using the relationJoins preview feature
Thanks for the report, and all the included information - that should allow us to reproduce the problem. |
@janpio Here's the full error with log level
|
Thank you! |
I just ran into this issue as well trying out My query looks like: const result = await prisma.matchboxEvent.findFirst({
where: { college_tradition_event: { subdomain } },
include: { college_tradition_event: true },
}); My schema looks like: model MatchboxEvent {
id String @id @default(uuid())
college_tradition_event CollegeTraditionEventMeta?
// ...
}
model CollegeTraditionEventMeta {
matchbox_event MatchboxEvent @relation(fields: [matchbox_event_id], references: [id])
matchbox_event_id String @unique
subdomain String? @unique
// ...
} Trace
Versions
|
Option::unwrap()
on a None
value when using the relationJoins preview featureOption::unwrap()
on a None
value when using the relationJoins preview feature with driver adapters
Same issue (
Fixed for me by swapping to the new join method Only affected one query (
|
Cause identified (at least in my case) - this error occurs when the included relation returns empty (null) fields - i.e. the generated Json column in the result contains things like The error goes away when I specify specific relation fields to return and omit the null fields, e.g.:
|
…1934) Hi 👋🏻, Alberto from @prisma here. We are users of the `serde-json` feature in [https://github.com/prisma/prisma-engines](https://github.com/prisma/prisma-engines/blob/23fdc5965b1e05fc54e5f26ed3de66776b93de64/Cargo.toml#L55-L60). ## The Problem While investigating a [user-reported Prisma issue](prisma/prisma#22294), we noticed that napi.rs treats `null` values in `Object` like `undefined` ones. However, `null` and `undefined` are semantically different in JavaScript: - `undefined` indicates that a value is not set - `null` indicates that a value has been explicitly set This PR, which we tested internally, fixes the user's issue on Prisma, and hopefully provides value to the `napi-rs` project as a whole. ## Scenario Consider [this scenario](https://github.com/prisma/prisma-engines/blob/dcb8cb9817af92fefaf0f95117dfb5dc19545a2c/query-engine/driver-adapters/src/napi/result.rs#L32-L33), effectively equivalent to: ```rust let napi_env: napi::sys::napi_env = /* ... */; let value: JsUnknown = object.get_named_property("value")?; // napi.rs implements the `FromNapiValue` trait for `serde_json` if // the `serde_json` feature is enabled (which we use already). let json = serde_json::Value::from_napi_value(napi_env, value.raw())?; Ok(Self::Ok(json.into())); ``` By looking at `napi.rs`' [`serde.rs` source file](https://github.com/napi-rs/napi-rs/blob/napi%402.12.4/crates/napi/src/bindgen_runtime/js_values/serde.rs), we [can see](https://github.com/napi-rs/napi-rs/blob/napi%402.12.4/crates/napi/src/bindgen_runtime/js_values/serde.rs#L104-L108) that "JSON subobjects" (`Map<String, serde_json::Value>`) are populated only if the value returned by `JsObject::get` is not `None`. This implies that, given `napi-rs`' [`Object::get` definition](https://github.com/napi-rs/napi-rs/blob/napi%402.12.4/crates/napi/src/bindgen_runtime/js_values/object.rs#L24-L44), `Object::get("key")` returns `None` both when the original object is ```js { // "key" is `undefined` } ``` and when the object is ```js { "key": null } ``` It just so happens that `prisma-engines` explicitly set a few `null` values explicitly for the features it offers, but these values are stripped away when we use the [napi-flavoured Prisma Query Engine](https://github.com/prisma/prisma-engines/tree/main/query-engine/query-engine-node-api). --- I am available for further comments, clarifications, and refactorings. Have a good day!
@jkomyno I noticed some good progress in this PR. Is this slated for the next prisma release? Looks like this was released as of napi@2.15.1 |
This should be fixed by napi-rs/napi-rs#1934 and prisma/prisma-engines#4687 and the fix will be released in the stable 5.10.0 release. You can also use I'll go ahead and close the issue, please let us know if the fix works for you or if you still face the problem! |
Bug description
I updated to
5.7.0
today and tried the preview featuresrelationJoins
andnativeDistinct
. I'm also usingdriverAdapters
with Neon DB.I am attempting to do a prisma
findFirst
with some nested includes:If I point the DB to my local, non-Neon DB everything works fine.
However when I point it to my Neon DB I get the following error:
How to reproduce
Environment & setup
@prisma/adapter-neon
and@neondatabase/serverless
Prisma Version
The text was updated successfully, but these errors were encountered: