mongoid-history icon indicating copy to clipboard operation
mongoid-history copied to clipboard

wrong number of arguments

Open francelwebdev opened this issue 4 years ago • 14 comments

Hi, This gem supports Mongoid 7?

francelwebdev avatar Apr 06 '20 16:04 francelwebdev

From README, "This gem supports Mongoid 3, 4, 5 on Ruby 1.9.3 or newer and Mongoid 6 and 7 on Ruby 2.2.2+." and Travis CI, https://github.com/mongoid/mongoid-history/blob/master/.travis.yml#L15.

However if I am reading your mind correctly you're having issues with Mongoid 7.1, similar to https://github.com/mongoid/mongoid-locker/issues/85. Appreciate a pull request with a fix.

dblock avatar Apr 06 '20 19:04 dblock

Good evening, I get this error (wrong number of arguments (given 2, expected 1)) when I go to the index page of my companies controller. Below the code of my company model. I use ruby 2.7.1 and Rails 6.0.2.2 and latest mongoid-history.

`class Company

include Mongoid::Document
include Mongoid::Timestamps

# include Mongoid::Attributes::Dynamic

include Mongoid::History::Trackable

field :name, type: String
field :roles, type: Array
field :website, type: String
field :address, type: String
field :country, type: String
field :phone_number, type: String
field :email_address, type: String
field :tax_identification_number, type: String
field :rccm, type: String

paginates_per 1

track_history(:on => [:fields]) # all fields will be tracked

index({name: 1, tax_identification_number: 1, rccm: 1, email_address: 1, phone_number: 1, website: 1}, {unique: true})

has_many :contacts, class_name: "Contact", dependent: :delete_all

accepts_nested_attributes_for :contacts, reject_if: :all_blank, allow_destroy: true

has_many :customer_proformas, class_name: 'CustomerProforma', dependent: :delete_all

has_many :supplier_proformas, class_name: 'SupplierProforma', dependent: :delete_all

has_many :purchase_orders, class_name: "PurchaseOrder", dependent: :delete_all

has_many :customer_invoices, class_name: 'CustomerInvoice', dependent: :delete_all

has_many :supplier_invoices, class_name: 'SupplierInvoice', dependent: :delete_all

validates :name, presence: true, uniqueness: { case_sensitive: false }
validates :roles, presence: true
validates :phone_number, uniqueness: true, allow_blank: true
validates :email_address, uniqueness: true, allow_blank: true
validates :website, uniqueness: true, allow_blank: true
validates :tax_identification_number, uniqueness: true, allow_blank: true
validates :rccm, uniqueness: true, allow_blank: true

before_create :transformer_le_nom_de_lentreprise_en_majuscule

private

def transformer_le_nom_de_lentreprise_en_majuscule
	self.name.upcase!
end

end `

francelwebdev avatar Apr 07 '20 15:04 francelwebdev

Please help. Make a PR that uses Mongoid 7.1, demonstrate the failure, try to fix.

dblock avatar Apr 07 '20 15:04 dblock

This is a bug in Mongoid 7.1.0. https://jira.mongodb.org/browse/MONGOID-4849

cgriego avatar Apr 10 '20 22:04 cgriego

Hello, Okay, thank you. I'm going to try this to see if it solves the problem. Thanks again.

francelwebdev avatar Apr 14 '20 09:04 francelwebdev

I am now using version 7.0.6 of Mongoid and I get this error (undefined method `collection_name' for Company:Class) when I update the index page of the controller companies.

francelwebdev avatar Apr 14 '20 12:04 francelwebdev

@francelwebdev Help us help you?

  1. Check out the code for this project, and run it with mongoid 7.0.6 (export MONGOID_VERSION=7.0.6, bundle install, rake) and see what fails.
  2. Add mongoid 7.0.6 to https://github.com/mongoid/mongoid-history/blob/master/.travis.yml and PR that. Let's confirm CI fails the same unit tests.
  3. Repeat with 7.1.
  4. Fix the bugs by implementing the workarounds. If we are sure it's too hard, we can punt and document.

dblock avatar Apr 14 '20 13:04 dblock

Hi, I still haven't found a solution to my problem. When I make rails console and instantiate my model with CustomerProforma.new, I get this error: ArgumentError: wrong number of arguments (given 2, expected 1) from /home/francel/.asdf/installs/ruby/2.7.1/lib/ruby/2.7.0/forwardable.rb:130:in instance_delegate' `.

francelwebdev avatar Apr 27 '20 16:04 francelwebdev

ArgumentError: wrong number of arguments (given 2, expected 1) from /home/francel/.asdf/installs/ruby/2.7.1/lib/ruby/2.7.0/forwardable.rb:130:in instance_delegate' `

please help me solve the problem.

francelwebdev avatar Apr 27 '20 17:04 francelwebdev

@francelwebdev Did you do what I suggested in https://github.com/mongoid/mongoid-history/issues/238#issuecomment-613456001?

dblock avatar Apr 27 '20 22:04 dblock

Sorry, I am a beginner and I do not master that. Here is the project repository. https://github.com/francelwebdev/jmaplus_erp_crm.git

francelwebdev avatar Apr 28 '20 10:04 francelwebdev

This project is a safe place for you to try and figure it out @francelwebdev! Here to help. You should definitely be able to do 1-3 above. I'll do my best to look at a fix if you can get those in.

dblock avatar May 01 '20 21:05 dblock

FYI I have a project that uses Mongoid 7.1.2 and mongoid-history 0.8.2, I don't think I read history in any capacity but at least everything loads and I assume writes.

p-mongo avatar Jun 11 '20 19:06 p-mongo

Hi,

I've been experiencing the same issue when trying to upgrade my app to Rails 6.

I cloned mongoid-history's repository and ran the tests as suggested by @dblock in this comment. I could not reproduce any problems there. Everything worked well and the tests passed.

After more investigation, I noticed that in my case this problem only happens in classes that include both Mongoid::History::Trackable and Mongoid::Locker, such as:

class Foo
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Locker
  include Mongoid::History::Trackable
  
  track_history on: [:all], modifier_field_optional: true
end

The including order does not make any difference. However, if you call track_history before including the Mongoid::Locker, it will work fine:

class Test
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::History::Trackable
  
  track_history on: [:all], modifier_field_optional: true
  
   include Mongoid::Locker
end

A similar workaround is suggested here.


Below are the versions of related gems:

  • rails (6.1.4.7)
  • activemodel (6.1.4.7)
  • mongoid-locker (2.0.1)
  • mongoid-history (0.8.5)
  • mongoid (7.3.4)

Current fix:

  • Downgrade the mongoid-locker to 2.0.0

arthurmde avatar Mar 09 '22 17:03 arthurmde