Deserialization does not respect optional fields for special types for raw queries #998
Labels
bug/2-confirmed
We have confirmed that this is a bug.
kind/bug
A reported bug.
topic: client
Related to the Client API
Bug description
If a field can be null/
None
and is specially handled with theDESERIALIZERS
variable found inprisma/_raw_query
(ie BigInt, Decimal, Json), then any raw queries which has said field and is null will error out.This only happens on 0.14.0 and above, as raw queries were reworked for that version.
How to reproduce
None
value forbad_var
:The bug should occur at this step.
Expected behavior
For raw queries including these nullable types to work.
Prisma information
Schema: https://github.com/AstreaTSS/PYTHIA/blob/8873fd94c770c9faa503c70201c01af3a0390943/schema.prisma
Models (there is some post-generation adjustments that I do to them - it has no effect on this bug but I might as well include everything): https://github.com/AstreaTSS/PYTHIA/blob/8873fd94c770c9faa503c70201c01af3a0390943/common/models.py
Query:
Environment & setup
Internal cause
Doing some investigation on my own, I found the culprit of the bug -
_deserialize_prisma_object
insrc/prisma/_raw_query.py
:prisma-client-py/src/prisma/_raw_query.py
Lines 122 to 166 in f1ab3b1
More specifically, focusing in on the non-array handling (essentially a single line), we get this:
From my understanding, what this does is:
prisma_type
(which I think is gathered from the model or from Prisma proper - point is, it's gotten independently of the actual query result) is in theDESERIALIZERS
mentioned earlier (though aliased under_deserializers
).Note that this makes no check to see if the value is, say,
None
. Interestingly enough, arrays do check forNone
, meaning it won't occur there.Anyways, a potential fix is just to hoist that
None
check for arrays to above the conditional statement, making it run for all values regardless of type. I was unsure if that fixes the issue in every case, and I'm unsure if that's necessarily the way it should be fixed, hence this issue.The text was updated successfully, but these errors were encountered: