Skip to content
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

PG::UndefinedColumn: ERROR: column "nan" does not exist #368

Open
Amnesthesia opened this issue May 21, 2023 · 3 comments
Open

PG::UndefinedColumn: ERROR: column "nan" does not exist #368

Amnesthesia opened this issue May 21, 2023 · 3 comments

Comments

@Amnesthesia
Copy link

Heyo @magnusvk, first of all I'm sorry about how vague this bug report is about to be, but it really is all I've got.

At some point we experienced some inconsistencies with the counter culture counts and added a Sidekiq worker that would run at night and fix the counts up if there were any discrepancies. We use AppSignal to track our errors, and an error that periodically comes up for us is this:

PG::UndefinedColumn: ERROR:  column "nan" does not exist
LINE 1: UPDATE "invoices" SET total_cost = NaN WHERE "invoices"."id"...

Narrowing this down, it comes from this:

  InvoiceItem.counter_culture_fix_counts(where: { account_id: account.id }, only: :invoice)
rescue => e
  Appsignal.set_error(e)
end

For reference, here's the relevant schema columns:

create_table "invoice_items", force: :cascade do |t|
   ... # other columns
   t.decimal "total", precision: 9, scale: 3
end

create_table "invoices", force: :cascade do |t|
   ... # other columns
  t.decimal "total_cost", default: "0.0"
end

And the relevant counter_culture definitions

# app/models/invoice_item.rb
class InvoiceItem < ApplicationRecord
   counter_culture :invoice, column_name: 'total_cost', delta_column: 'total', touch: true
end

I cannot for the life of me reproduce this locally in any way. I can't figure out how it would be possible for this to become NaN. I've tried:

  • Creating an invoice with an invoice item with a total of 1.7976931348623157e+308 (max Float value), and adding a second one to try to "overflow" it (still not NaN)
  • Forcibly setting InvoiceItem.total to NULL
  • Both of the above at once

This error keeps popping up and I can't in any way make it evaluate to NaN, so this bug report may be completely useless to you, but as a last resort I thought I'd open this issue and see if you have any suggestions or thoughts on how this could possibly become NaN and throw this error?

@magnusvk
Copy link
Owner

The query that pulls that value is here and is just

"SUM(COALESCE(#{self_table_name}.#{delta_column}, 0))"

I've never seen NaN in Postgres before, but a tiny bit of googling suggests that maybe some of the values you are summing end up as NaN is that possible?

@Amnesthesia
Copy link
Author

@magnusvk it must be, but I cant figure out what values I could sum to produce NaN, I can't figure out a way to reproduce it locally

@magnusvk
Copy link
Owner

I don't see any indication that this is caused by counter_culture, and nobody else has reported this before. I'm going to close this issue since I don't think I'll be able to help here, but feel free to follow up if you can repro this somehow and tie it to counter_culture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants