Ruby Sequel with Postgresql: How do I remove reference to an 'undefinedtable' - ruby

Hi: I need to remove a reference to a table that is incorrect but I cannot find where that reference is stored.
I am using ruby 2.6.0, sequel 5.30.0 and postgres 13 and Sinatra 2.0.8.
I mistakenly referred to a table with a misspelling in one of my migration files, ran the migrator and now I am getting an error that the table (with the misspelled name) does not exist when I try to run the application.
Sequel::DatabaseError: PG::UndefinedTable: ERROR: relation "renew_event_types" does not exist
I corrected the misspelled reference in my migration (it should be "renewal_event_types"), ran the migrations back to the one before this then reran all the migrations forward and I still get the error. I dropped the database, ran the migrations again and still get the error. I cannot find any file with the word "renew_event_types" in it on my system so I believe that somehow this reference is not in ascii format. If it was stored in Postgres, it should have been removed when I dropped the database. Would it be stored in a sequel file somewhere associated with this project?
Here is the parc-mbr/app/renewalEventType.rb where I initially spelled the reference to the foreign key "renew_event_type_id" then changed it to "renewal_event_type_id" to reflect the correct table "renewal_event_type" (note change from renew to renewal).
require_relative '../config/sequel'
module MemberTracker
class RenewEventType < Sequel::Model
one_to_many :mbr_renewals, :class=>"MemberTracker::MbrRenewal", key: :renewal_event_type_id
many_to_one :auth_users, :class=> "MemberTracker::Auth_user", key: :a_user_id
end
end
Here is the other associated model file parc-mbr/app/mbrRenewal.rb
require_relative '../config/sequel'
module MemberTracker
class MbrRenewal < Sequel::Model
one_to_many :log, :class =>"MemberTracker::Log", key: :mbr_renewal_id
many_to_one :auth_user, :class=>Auth_user, key: :a_user_id
many_to_one :member, :class=>Member, key: :mbr_id
many_to_one :renewalEventType
def getRenewalTypeIDs
DB.from(:renewal_event_types).select(:id, :name).all
end
end
end
Here is the full trace in my terminal. Thanks for any pointers on how to begin to solve this problem.
2022-09-18 16:06:06.135 PDT [1837] ERROR: relation "renew_event_types" does not exist at character 1133
2022-09-18 16:06:06.135 PDT [1837] STATEMENT: SELECT "pg_attribute"."attname" AS "name", CAST("pg_attribute"."atttypid" AS integer) AS "oid", CAST("basetype"."oid" AS integer) AS "base_oid", format_type("basetype"."oid", "pg_type"."typtypmod") AS "db_base_type", format_type("pg_type"."oid", "pg_attribute"."atttypmod") AS "db_type", pg_get_expr("pg_attrdef"."adbin", "pg_class"."oid") AS "default", NOT "pg_attribute"."attnotnull" AS "allow_null", COALESCE(("pg_attribute"."attnum" = ANY("pg_index"."indkey")), false) AS "primary_key", "pg_attribute"."attidentity" FROM "pg_class" INNER JOIN "pg_attribute" ON ("pg_attribute"."attrelid" = "pg_class"."oid") INNER JOIN "pg_type" ON ("pg_type"."oid" = "pg_attribute"."atttypid") LEFT OUTER JOIN "pg_type" AS "basetype" ON ("basetype"."oid" = "pg_type"."typbasetype") LEFT OUTER JOIN "pg_attrdef" ON (("pg_attrdef"."adrelid" = "pg_class"."oid") AND ("pg_attrdef"."adnum" = "pg_attribute"."attnum")) LEFT OUTER JOIN "pg_index" ON (("pg_index"."indrelid" = "pg_class"."oid") AND ("pg_index"."indisprimary" IS TRUE)) WHERE (("pg_attribute"."attisdropped" IS FALSE) AND ("pg_attribute"."attnum" > 0) AND ("pg_class"."oid" = CAST(CAST('"renew_event_types"' AS regclass) AS oid))) ORDER BY "pg_attribute"."attnum"
2022-09-18 16:06:06.135 PDT [1837] ERROR: relation "renew_event_types" does not exist at character 15
2022-09-18 16:06:06.135 PDT [1837] STATEMENT: SELECT * FROM "renew_event_types" LIMIT 1
bundler: failed to load command: rackup (/Users/megazoic/.rbenv/versions/2.6.6/bin/rackup)
Sequel::DatabaseError: PG::UndefinedTable: ERROR: relation "renew_event_types" does not exist
LINE 1: SELECT * FROM "renew_event_types" LIMIT 1
^
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:156:in `exec'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:156:in `block in execute_query'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/database/logging.rb:38:in `log_connection_yield'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:156:in `execute_query'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:144:in `block in execute'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:120:in `check_disconnect_errors'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:144:in `execute'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:500:in `_execute'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:318:in `block (2 levels) in execute'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:522:in `check_database_errors'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:318:in `block in execute'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/connection_pool/threaded.rb:88:in `hold'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/database/connecting.rb:270:in `synchronize'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:318:in `execute'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/dataset/actions.rb:1089:in `execute'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/adapters/postgres.rb:614:in `fetch_rows'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/dataset/actions.rb:152:in `each'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/dataset/actions.rb:86:in `columns!'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/dataset/actions.rb:76:in `columns'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:242:in `columns'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:811:in `block (2 levels) in get_db_schema'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:725:in `block in check_non_connection_error'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/database/transactions.rb:201:in `block in transaction'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/connection_pool/threaded.rb:92:in `hold'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/database/connecting.rb:270:in `synchronize'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/database/transactions.rb:195:in `transaction'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:725:in `check_non_connection_error'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:811:in `block in get_db_schema'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:844:in `get_db_schema'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:644:in `set_dataset'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/sequel-5.30.0/lib/sequel/model/base.rb:499:in `inherited'
/Users/megazoic/Documents/dev/proj/versioned/ruby/parc-mbr/app/renewalEventType.rb:4:in `<module:MemberTracker>'
/Users/megazoic/Documents/dev/proj/versioned/ruby/parc-mbr/app/renewalEventType.rb:3:in `<top (required)>'
/Users/megazoic/Documents/dev/proj/versioned/ruby/parc-mbr/app/api.rb:20:in `require_relative'
/Users/megazoic/Documents/dev/proj/versioned/ruby/parc-mbr/app/api.rb:20:in `<top (required)>'
/Users/megazoic/Documents/dev/proj/versioned/ruby/parc-mbr/config.ru:1:in `require_relative'
/Users/megazoic/Documents/dev/proj/versioned/ruby/parc-mbr/config.ru:1:in `block in <main>'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `eval'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `new_from_string'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:105:in `load_file'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:66:in `parse_file'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:349:in `build_app_and_options_from_config'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:249:in `app'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:422:in `wrapped_app'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:312:in `block in start'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:379:in `handle_profiling'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:311:in `start'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/lib/rack/server.rb:168:in `start'
/Users/megazoic/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rack-2.2.2/bin/rackup:5:in `<top (required)>'
/Users/megazoic/.rbenv/versions/2.6.6/bin/rackup:23:in `load'
/Users/megazoic/.rbenv/versions/2.6.6/bin/rackup:23:in `<top (required)>'

My error was to leave the model name unchanged (class RenewEventType) even though I had changed the creation of the associated table in the migration files and the reference to the foreign key in the model description. Ruby and presumably Sequel used this name of the model to look for the corresponding table that hadn't been created. Thanks #spikermann for pointing me in the right direction.

Related

ActiveRecord: no such table for unrelated table, but only on one server

I'm trying to set an attribute in an ActiveRecord table. I have the following file which works on one server, but gives an error on the other.
require 'active_record'
require 'sqlite3'
require_relative 'models/master'
$CONFIG = YAML.load_file('config.yml').freeze
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection($CONFIG[:connection])
s = Stock.find_by(isbn: 1234)
s.status = 'CHECKED_OUT'
s.save!
Both versions have the same database, the same code, etc. through git. However, on the second server I get the following error:
/home/web/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in `initialize': SQLite3::SQLException: no such table: main.book: UPDATE "stock" SET "status" = ? WHERE "stock"."ROWID" = ? (ActiveRecord::StatementInvalid)
from /home/web/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in `new'
from /home/web/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in `prepare'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:212:in `block (2 levels) in exec_query'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:209:in `block in exec_query'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
from /home/web/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:208:in `exec_query'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:239:in `exec_delete'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:140:in `update'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/relation.rb:85:in `_update_record'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/persistence.rb:575:in `_update_record'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/locking/optimistic.rb:80:in `_update_record'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/attribute_methods/dirty.rb:292:in `_update_record'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/callbacks.rb:344:in `block in _update_record'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:131:in `run_callbacks'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:827:in `_run_update_callbacks'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/callbacks.rb:344:in `_update_record'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/timestamp.rb:107:in `_update_record'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/persistence.rb:563:in `create_or_update'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/callbacks.rb:336:in `block in create_or_update'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:131:in `run_callbacks'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:827:in `_run_save_callbacks'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/callbacks.rb:336:in `create_or_update'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/persistence.rb:162:in `save!'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/validations.rb:50:in `save!'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/attribute_methods/dirty.rb:43:in `save!'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:313:in `block in save!'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:384:in `block in with_transaction_returning_status'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
from /home/web/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:381:in `with_transaction_returning_status'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:313:in `save!'
from /home/web/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/suppressor.rb:46:in `save!'
from test.rb:12:in `<main>'
D, [2018-02-04T19:36:39.046660 #26810] DEBUG -- : [1m[36mStock Load (0.2ms)[0m [1m[34mSELECT "stock".* FROM "stock" WHERE "stock"."isbn" = ? LIMIT ?[0m [["isbn", 1234], ["LIMIT", 1]]
D, [2018-02-04T19:36:39.055100 #26810] DEBUG -- : [1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
D, [2018-02-04T19:36:39.056339 #26810] DEBUG -- : [1m[35mSQL (0.3ms)[0m [1m[33mUPDATE "stock" SET "status" = ? WHERE "stock"."ROWID" = ?[0m [["status", "CHECKED_OUT"], ["ROWID", 1]]
D, [2018-02-04T19:36:39.056522 #26810] DEBUG -- : [1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
The interesting thing is that the table it says doesn't exist is not used at all in the query (as you can see in the logged queries). The Stock model has a belongs_to :book, foreign_key: 'isbn' which stops the error when removed. However, changing any column other than status does not cause the error.
The servers do have different versions of ActiveRecord and SQLite, however I am more interested in why this behavior is occurring so that I can prevent it in the future. The code works on ActiveRecord 2.6.8, but fails on 2.6.14. Is there any obvious reason why this would happen?

Cannot reindex with Searchkick

My database has over 3 million documents to be indexed. This is my setup:
Rails 4.2.0beta2 on Heroku. Using Searchkick with Found Heroku addon.
These are the models that I indexed:
class Item
searchkick text_start: [:n, :ot, :est]
def search_data
# as_json only: [:n, :ot, :est, :dst, :d, :a]
{
n: n,
ot: detail.ot,
est: detail.est,
dst: dst,
d: detail.d,
a: detail.a
}
end
end
class User
searchkick text_start: [:full_name]
def full_name
"#{first_name} #{last_name}"
end
def search_data
{
full_name: full_name
}
end
end
.. by doing rake searchkick:reindex:all.
Now, I've noticed that our Elasticsearch cluster has only indexed half of my documents (~1.5M). I asked our cluster provider if there is any limit on number of documents and confirmed that there isn't. I don't know why it stopped at 1.5M (instead of indexing all 3 million). However, now I'm trying to index everything again and watch out for errors or something alike and this is the first thing it comes out (before indexing anything):
NameError: undefined local variable or method `index' for #<Searchkick::Index:0x007fbb5308bf18>
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/index.rb:192:in `block in import_scope'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:648:in `yield_document'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:123:in `block in each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:32:in `block in each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:32:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:32:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/moped-2.0.3/lib/moped/query.rb:77:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:122:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual.rb:20:in `each'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/index.rb:189:in `import_scope'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/index.rb:158:in `reindex_scope'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/searchkick-0.8.6/lib/searchkick/model.rb:47:in `reindex'
from (irb):1
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
... 7 levels...
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/commands/rails.rb:6:in `call'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/command_wrapper.rb:38:in `call'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:183:in `block in serve'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:156:in `fork'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:156:in `serve'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:131:in `block in run'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:125:in `loop'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application.rb:125:in `run'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.3.1/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
Checking out cluster status once this error comes out, I see that a new index is created instead of "overriding" the old one: http://cl.ly/image/0I0v1a2T1N2W
What I'm doing wrong? Any ideas on how to solve this?
Thanks in advance.

In 'initialize': wrong number of arguments (1 for 2..3) (ArgumentError)

So I have the class 'Range' created by Datamapper (this is in a Ruby/Sinatra project):
class Range
include DataMapper::Resource
#properties
property :id, Serial, :key => true
property :default_gateway, String
property :subnetmask, String
property :main_ip, String
property :backup_ip, String
property :dhcp, String
#relations
belongs_to :vlan, :required => true
has n, :dhcp
end #class Range
I also have a file 'initdata' which I call in my main class. A part of this file tries to fill up the database with some dummy data. The problem is with the class Ranges it gives me an ArgumentError.
Initdata ruby file:
#CREATE RANGES
if Range.count == 0
puts '----- ADDING RANGES -----'
range1 = Range.first_or_create(:default_gateway => '10.1.2.44', :subnetmask => '0.0.255.255', :main_ip => '10.1.0.1', :backup_ip => '10.1.0.2', :dhcp => '192.168.1.2', :vlan_id => 1)
range1.errors.each do |error|
puts error
end
end
I get the following error when I run it in the terminal:
----- ADDING RANGES -----
/home/bene/.rvm/gems/ruby-2.1.3/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `initialize': wrong number of arguments (1 for 2..3) (ArgumentError)
from /home/bene/.rvm/gems/ruby-2.1.3/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `new'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `create'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/dm-core-1.2.0/lib/dm-core/model.rb:444:in `first_or_create'
from /home/bene/project/development_sam/lan_portal/dal/initdata.rb:328:in `<top (required)>'
from /home/bene/project/development_sam/lan_portal/app.rb:6:in `require'
from /home/bene/project/development_sam/lan_portal/app.rb:6:in `<top (required)>'
from /home/bene/project/development_sam/lan_portal/config.ru:1:in `require'
from /home/bene/project/development_sam/lan_portal/config.ru:1:in `block in <main>'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /home/bene/project/development_sam/lan_portal/config.ru:in `new'
from /home/bene/project/development_sam/lan_portal/config.ru:in `<main>'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:250:in `start'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/lib/rack/server.rb:141:in `start'
from /home/bene/.rvm/gems/ruby-2.1.3/gems/rack-1.5.2/bin/rackup:4:in `<top (required)>'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/rackup:23:in `load'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/rackup:23:in `<main>'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'
from /home/bene/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'
Does anyone have any idea what I might be doing wrong? I've searched for it, but most solutions are because people wrote their own 'initialize' function, as in my case, it's already defined by DataMapper
There is a core Ruby class Range (which, incidentally, has a 2..3-argument constructor); Appearently, DataMapper does not redefine a constructor if one already exists.
You need to rename your class.

How to fix ActiveRecord::DangerousAttributeError when checking pending migration in RSpec spec_helper?

Okay so this is a new one. RSPec. Rails 4.
This line is in my spec_helper.rb:
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
When I run a simple test (on an ActiveRecord model):
it { should respond_to :activity }
I get the following error & trace:
/Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord 4.0.0/lib/active_record/attribute_methods.rb:59:in `instance_method_already_implemented?': version is defined by Active Record (ActiveRecord::DangerousAttributeError)
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_method'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `define_attribute_method'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `block in define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:29:in `block in define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `synchronize'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:167:in `respond_to?'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:368:in `__define_callbacks'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:79:in `run_callbacks'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/core.rb:216:in `init_with'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/persistence.rb:55:in `instantiate'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `block in find_by_sql'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `block in each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `map'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `find_by_sql'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:585:in `exec_queries'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in `load'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:220:in `to_a'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:12:in `map'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:787:in `get_all_versions'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:793:in `current_version'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
from /projects/subset_of_projects/this_project_group/projectname/spec/spec_helper.rb:17:in `<top (required)>'
I'd added the paper_trail gem but not run the install/migrations. Simple and obvious really. But it wasn't an error I'd seen before so I'll post this so others who might run into it can check the obvious before wasting a long time on this.

howto parse nested json attributes with activeresource

i am trying to parse the following jsons response via activeresource in the padrino framework from a rest-api:
{"result":"Ok","resource":"ProjectRazor::Slice::Model","errcode":0,"command":"models_query_all","response":[{"#uri":"http://192.168.0.50:8026/razor/api/model/5nBqgTngqvxPIxVJJpdeQm","#callback":{},"#version":2,"#uuid":"5nBqgTngqvxPIxVJJpdeQm","#description":"Ubuntu Precise Model","#domainname":"andreasheumaier.de","#counter":0,"#broker_plugin":"agent","#root_password":"/7bbNwa6","#log":[],"#policy_bound":null,"#hostname_prefix":"firebird","#classname":"ProjectRazor::ModelTemplate::UbuntuPrecise","#osversion":"precise","#is_template":false,"#final_state":"os_complete","#node":null,"#req_metadata_hash":{"#domainname":{"validation":"^[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9](\\.[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])*$","example":"example.com","required":true,"description":"local domain name (will be used in /etc/hosts file)","default":"localdomain"},"#root_password":{"validation":"^[\\S]{8,}","example":"P#ssword!","required":true,"description":"root password (> 8 characters)","default":"test1234"},"#hostname_prefix":{"validation":"^[a-zA-Z0-9][a-zA-Z0-9\\-]*$","example":"node","required":true,"description":"node hostname prefix (will append node number)","default":"node"}},"#hidden":false,"#name":"ubuntu_precise","#label":"install_precise","#current_state":"init","#result":null,"#template":"linux_deploy","#noun":"model","#image_prefix":"os","#image_uuid":"4VuDj4mJDHP6bvWeztfXOO"}],"http_err_code":200}
I defined this models
class RazorJsonFormatter
include ActiveResource::Formats::JsonFormat
def decode(json)
ActiveResource::Formats::JsonFormat.decode(json)['response']
end
end
class Razor < ActiveResource::Base
include ActiveResource::Formats::JsonFormat
include ActiveResource::Extend::WithoutExtension
self.format = RazorJsonFormatter.new
self.site = "http://yellowbird:8026/razor/api/"
end
class RazorModel < Razor
set_collection_name 'model'
end
This gives following error:
RazorModel.all
NameError: wrong constant name #callback
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1428:in `const_defined?'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1428:in `find_or_create_resource_for'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1278:in `block in load'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1264:in `each'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1264:in `load'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:1006:in `initialize'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:933:in `new'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:933:in `instantiate_record'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:929:in `block in instantiate_collection'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:929:in `collect!'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:929:in `instantiate_collection'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:901:in `find_every'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:814:in `find'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:826:in `first'
from (irb):27
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/padrino-core-0.10.7/lib/padrino-core/cli/base.rb:68:in `console'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/invocation.rb:109:in `invoke'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/padrino-core-0.10.7/lib/padrino-core/cli/base.rb:73:in `c'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/gems/padrino-core-0.10.7/bin/padrino:9:in `<top (required)>'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/bin/padrino:19:in `load'
from /home/aheumaier/.rvm/gems/ruby-1.9.3-p194/bin/padrino:19:in `<main>'1.9.3p194
(...)
This either works with predifined ActiveResource schema. My current workaround is write all classes from scratch using rest-client
How can parse -or igore- the nested json attributes with activeresource?

Resources