Coder Social home page Coder Social logo

Deserializing `Decimal`s from Postgres using the `db-postgres` feature can lead to invalid `Decimal` instances about rust-decimal HOT 4 CLOSED

klevente avatar klevente commented on June 25, 2024 1
Deserializing `Decimal`s from Postgres using the `db-postgres` feature can lead to invalid `Decimal` instances

from rust-decimal.

Comments (4)

paupino avatar paupino commented on June 25, 2024 2

Thank you for raising this - it's a very interesting edge case. I've created a fix for this which effectively bounds the scale at 28. While there are some legitimate cases for a scale of 29 - it can cause undefined behavior so we typically avoid anything above 28. Consequently, after bounding it - things work "as expected" (assuming rounding to fit into the decimal type is desired).

from rust-decimal.

Tony-Samuels avatar Tony-Samuels commented on June 25, 2024 1

I've seen bugs raised around this behaviour before but thought it was fixed by this MR.

I'm able to reproduce it via your repo though, so there's probably a second issue there too. It's not a regression since that change, as I can reproduce it directly on the fix commit.

FYI: If anyone else hits issues starting the docker container, switch the image from postgres to postgres:12-bullseye.

from rust-decimal.

klevente avatar klevente commented on June 25, 2024

Hey @Tony-Samuels, thanks for the swift reply! If you need any more repro steps or anything else, please let me know. Unfortunately I'm not that well-versed in decimal handling, but I'll try looking into the code as well to see what might be going wrong.

from rust-decimal.

klevente avatar klevente commented on June 25, 2024

Thanks @paupino, really appreciate the fix! I think for this case, rounding is acceptable for now, until a configuration option or feature flag gets added where the user can control whether they'd like rounding or not - for me, rounding is perfectly fine.

from rust-decimal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.