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
Experimental support for the Decimal type #106
Comments
This is more difficult to do right than I initially anticipated. If we just naively serialise Due to how our query builder works we actually cannot warn or error when a I do not know the best solution for this issue at this point in time. |
Blocked by: prisma/prisma#10252 At this point in time I do not believe the workaround mentioned is a good enough solution. I also do not want to introduce any footguns. |
A solution I hadn't considered before for the aforementioned issue would be to simply process the data that prisma sends us and set the precision appropriate to that. However I do not know how decimal objects interact with each when the precision differs. This could also be confusing for consumers as the precision would be different for every object. |
How should we do currently if the Decimal type is not supported? |
@danielweil you just can't use it unfortunately. An alternative would be to use the String type at the database level and convert it to a decimal.Decimal yourself. |
Would you be willing to implement one of the workaround solutions while you work out the better long term fix? As is, I can't use this client at all since I cannot change the data type :( |
@tday Considering that two people have asked for this feature I am willing to implement a workaround solution, however I am quite busy at the moment so while a complete solution might not be available for a little while I have made the necessary changes required for minimal support. You can try it out by installing from the work in progress branch:
|
@RobertCraigie Thanks for the quick turnaround! I think you need to add a quick line to the
|
@tday Sorry about that, I've pushed the fix. |
Thanks! Confirmed this works for Decimal on the WIP branch. Given its sitting in a WIP feature branch, I was able to reduce my data type constraint down to |
Hey folks - wonder how we can help push this forward? @RobertCraigie are there any outstanding items in your branch that need to get done? Happy to help. |
I've spoken to the Prisma Team and while there is an open PR (prisma/prisma-engines#2660) to implement the internal feature required for us to be able to support However, as this does seem to be a popular feature request I'll talk to them again and in the meantime I'm willing to implement a workaround until a proper solution is agreed upon. In terms of what needs to be done before I can merge the in progress branch:
There may be other items but those are all that I can think of off the top of my head. @gakonst Thanks for offering to help! Please be wary that adding support for a new type touches the deepest parts of this codebase, some of which are in need of a refactor and may be confusing for anyone new to the codebase. Reading through the contributing documentation will help although it is not extensive. |
Why is this experimental?
Currently Prisma Client Python does not have access to the field metadata containing the precision of
Decimal
fields at the database level. This means that we cannot:Decimal
value with a greater precision than the database supports, leading to implicit truncation which may cause confusing errorsdecimal.Decimal
objects to match the database level, potentially leading to even more confusing errors.To try and mitigate the effects of these errors you must be explicit that you understand that the support for the
Decimal
type is not up to the standard of the other types. You do this by setting theenable_experimental_decimal
config flag, e.g.The text was updated successfully, but these errors were encountered: