Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

writing and reading rust_decimal::Decimal Number exceeds maximum value that can be represented. #1942

Closed
gitmalong opened this issue Oct 29, 2023 · 4 comments

Comments

@gitmalong
Copy link

gitmalong commented Oct 29, 2023

Hi!

I am inserting my Option<rust_decimal::Decimal> via the code below while volume is of type Decimal.

entities::prelude::MyEntity::update_many()
            .col_expr(
                myEntity::Column::Volume,
                Expr::value(Value::Decimal(Some(volume.into()))),
            )

which works fine.

But when reading rows from the table the app panics with

thread 'tokio-runtime-worker' panicked at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rust_decimal-1.32.0/src/decimal.rs:470:23:
Number exceeds maximum value that can be represented.
stack backtrace:
15:        0x10500b984 - core::panicking::panic_fmt::h3fc5ad127547e2b3
                               at /rustc/df871fbf053de3a855398964cd05fadbe91cf4fd/library/core/src/panicking.rs:72:14
  16:        0x1050085f0 - rust_decimal::decimal::Decimal::from_i128_with_scale::panic_cold_display::hfd9e6ce1ee2cd10e
  17:        0x104f9698c - rust_decimal::decimal::Decimal::from_i128_with_scale::h6c1a00be0be3d92e
  18:        0x104d7f60c - sqlx_postgres::types::rust_decimal::<impl core::convert::TryFrom<sqlx_postgres::types::numeric::PgNumeric> for rust_decimal::decimal::Decimal>::try_from::hc52b6925820be2f8
  19:        0x104d7f9e8 - sqlx_postgres::types::rust_decimal::<impl sqlx_core::decode::Decode<sqlx_postgres::database::Postgres> for rust_decimal::decimal::Decimal>::decode::hd9a3478e707acc77
  20:        0x104c139c4 - sqlx_core::row::Row::try_get::he57137519c5b9ff8
  21:        0x104c121cc - sea_orm::executor::query::TryGetable::try_get::hf252a8b61b7be3c3
  22:        0x104c1907c - sea_orm::executor::query::QueryResult::try_get::h13b7f2f1363a1537
  23:        0x104be2ab4 - <myapp::entities::ledger::Model as sea_orm::entity::model::FromQueryResult>::from_query_result::h3b4523db16e761a2

This confuses me as I inserted only Decimal values which I would have not been able to construct if invalid. It would also be helpful to see which exact number caused this issue as the Decimal crates error message does not print the number.

Sorry for not providing a exact reproducable example but I assume it can be done by trying to insert and read the Decimal's max value.

Database: Postgres 16

Versions

   └── sea-orm-migration v0.12.4
│       ├── sea-orm v0.12.4
│       │   ├── sea-orm-macros v0.12.5 (proc-macro)
│       │   │   ├── sea-bae v0.2.0 (proc-macro)
│       │   ├── sea-query v0.30.2
│       │   │   ├── sea-query-derive v0.4.1 (proc-macro)
│       │   ├── sea-query-binder v0.5.0
│       │   │   ├── sea-query v0.30.2 (*)
│       ├── sea-orm-cli v0.12.4
│       │   ├── sea-schema v0.14.1
│       │   │   ├── sea-query v0.30.2 (*)
│       │   │   └── sea-schema-derive v0.2.0 (proc-macro)
│       ├── sea-schema v0.14.1 (*)
├── sea-orm v0.12.4 (*)
├── sea-orm-migration v0.12.4 (*)
@gitmalong gitmalong changed the title Number exceeds maximum value that can be represented. writing and reading rust_decimal::Decimal Number exceeds maximum value that can be represented. Oct 29, 2023
@gitmalong
Copy link
Author

gitmalong commented Oct 29, 2023

Seems to be an issue on sqlx side: launchbadge/sqlx#666

How can I make use of this fix when it only landed in sqlx's main branch?

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 29, 2023

  1. Can you verify the database table or select expression does not yield a value that exceeds the valid range? If so, this is a bug in the protocol decode phase
  2. Otherwise, you can use BigDecimal, if a value exceeds the range of Decimal. And rust_decimal panicking is expected behaviour

@gitmalong
Copy link
Author

  1. Yes, I only inserted data via my SeaORM app and all inserts/updates (I just have two) use the Decimal type. Therefore it must be within a valid range.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2023

Therefore it must be within a valid range.

Can you verify that or make a reproducible example?

@SeaQL SeaQL locked and limited conversation to collaborators Dec 1, 2023
@tyt2y3 tyt2y3 converted this issue into discussion #1990 Dec 1, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants