jackc / pgtype

MIT License
308 stars 110 forks source link

Bug scanning Numeric in v1.14.1 #211

Closed kydemy-fran closed 7 months ago

kydemy-fran commented 8 months ago

I have a stored procedure that returns many columns and after the update. Some of those columns are Numeric (both nullable and not nullable).

Before the update (using 1.14.0 all was good), but after update and release, we have had some complaints from some customers.

I am using:

github.com/jackc/pgtype v1.14.1
github.com/jackc/pgx/v4 v4.18.1

I've created some tests to see what was happening. I am using the following struct:

type TestData struct {
    AccountID              int      `json:"account_id"`
    Amount                 float64  `json:"amount" kom:"`
    AmountBase             *float64 `json:"amount_base"`
    AmountVat              *float64 `json:"amount_vat"`
}

If I execute the following query directly in PostgreSQL 15.4:

SELECT account_id,amount,amount_base,amount_vat FROM payments.generate_remittances($1,$2);
The result is: account_id amount amount_base amount_vat
1230 50 50 0
1167 50 50 0
1715 25 25 0
1715 30 30 0
In v.1.14.1 all values for AccountID, AmountBase and AmountVat are correct. But some of the values scanned for Amount are wrong: AccountID Amount AmountBase AmountVAT
1230 5 50 0
1167 5 50 0
1715 25 25 0
1715 30 30 0
If I roll back to v1.14.0 the values are correct: AccountID Amount AmountBase AmountVAT
1230 50 50 0
1167 50 50 0
1715 25 25 0
1715 30 30 0

Let me know if you need further details.

I am going to rollback to v1.14.0, but it would be great if someone could take a look into this issue. Thank you!

jackc commented 8 months ago

Let me know if you need further details.

Two things could help.

  1. A test case that someone else could run.
  2. You could bisect between v1.14.0 and v1.14.1. As far as I can tell there are only 2 commits that should have affected numeric support so it should be pretty trivial to determine which is the problem.
kydemy-fran commented 8 months ago

I've been trying to do a test without dependencies, and I am not able to replicate. I am still able to replicate with my project/DB. I am unsure where the problem is. I'll need to do your second suggestion and debug both versions. Will do sometime later this week.

kydemy-fran commented 7 months ago

Confirmed, this issue has been resolved in v1.14.2 Thank you!