Search code examples
ruby-on-railsheroku-postgres

ActiveRecord::StatementInvalid: PG::NumericValueOutOfRange: ERROR: value "150000200000" is out of range for type integer


I am getting an error when running a rake on heroku. I can run rakes locally just fine but for some reason this isnt working in a live environment. I have seen some posts about bigint integers but I am not even sure where this error is occurring or why ?

C:\Sites\jeepjig>heroku rake scraper:scrape
Your version of git is 1.9.4.. Which has serious security vulnerabilities.
More information here: https://blog.heroku.com/archives/2014/12/23/update_your_git_clients_on_windows_and_os_x
WARNING: `heroku rake` has been deprecated. Please use `heroku run rake` instead.
Running `rake scraper:scrape` attached to terminal... up, run.8759
PG::NumericValueOutOfRange: ERROR:  value "150000200000" is out of range for type integer
: INSERT INTO "posts" ("body", "created_at", "external_url", "heading", "make", "mileage", "model", "price", "timestamp", "title_status", "transmiss
ion", "updated_at", "year") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING "id"
rake aborted!
ActiveRecord::StatementInvalid: PG::NumericValueOutOfRange: ERROR:  value "150000200000" is out of range for type integer
: INSERT INTO "posts" ("body", "created_at", "external_url", "heading", "make", "mileage", "model", "price", "timestamp", "title_status", "transmiss
ion", "updated_at", "year") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING "id"
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:834:in `get_last_result'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:834:in `block in exec_cache'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `exec_cache'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `exec_query'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:177:in `exec_insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:95:in `insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/relation.rb:64:in `insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/persistence.rb:503:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/attribute_methods/dirty.rb:87:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:306:in `block in _create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:215:in `block in halting_and_conditional'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:306:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/timestamp.rb:57:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/persistence.rb:483:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:166:in `block in halting'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:302:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/persistence.rb:103:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/validations.rb:51:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/attribute_methods/dirty.rb:21:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:268:in `block (2 levels) in save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transac
tion'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_trans
action'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:268:in `block in save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:267:in `save'
/app/lib/tasks/scraper.rake:62:in `block (4 levels) in <top (required)>'
/app/lib/tasks/scraper.rake:38:in `each'
/app/lib/tasks/scraper.rake:38:in `block (3 levels) in <top (required)>'
/app/lib/tasks/scraper.rake:13:in `loop'
/app/lib/tasks/scraper.rake:13:in `block (2 levels) in <top (required)>'
Tasks: TOP => scraper:scrape
(See full trace by running task with --trace)

Solution

  • "150000200000" is the value in one of the fields being inserted with INSERT INTO "posts" ("body", "created_at", "external_url", "heading", "make", "mileage", "model", "price", "timestamp", "title_status", "transmission", "updated_at", "year")... statement.

    The corresponding field should be changed from integer to bigint to resolve this issue. Or changed to string if the field doesn't have to be numeric.

    The issue not happening locally, but happening on heroku, is most likely because the Heroku scrape process is running against a site that is not included in the local script.

    Best to add additional logging/puts statements to identify which field is getting the value as "150000200000", and then deal with the field appropriately.