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

wrong number of arguments #238

Open
francelwebdev opened this issue Apr 6, 2020 · 14 comments
Open

wrong number of arguments #238

francelwebdev opened this issue Apr 6, 2020 · 14 comments
Labels

Comments

@francelwebdev
Copy link

Hi,
This gem supports Mongoid 7?

@dblock
Copy link
Collaborator

dblock commented Apr 6, 2020

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 mongoid/mongoid-locker#85. Appreciate a pull request with a fix.

@dblock dblock added the bug? label Apr 6, 2020
@francelwebdev
Copy link
Author

francelwebdev commented Apr 7, 2020

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
`

@dblock
Copy link
Collaborator

dblock commented Apr 7, 2020

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

@cgriego
Copy link
Contributor

cgriego commented Apr 10, 2020

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

@francelwebdev
Copy link
Author

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

@francelwebdev
Copy link
Author

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.

@dblock
Copy link
Collaborator

dblock commented Apr 14, 2020

@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 dblock added bug and removed bug? labels Apr 14, 2020
@francelwebdev
Copy link
Author

francelwebdev commented Apr 27, 2020

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
Copy link
Author

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.

@dblock
Copy link
Collaborator

dblock commented Apr 27, 2020

@francelwebdev Did you do what I suggested in #238 (comment)?

@francelwebdev
Copy link
Author

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

@dblock
Copy link
Collaborator

dblock commented May 1, 2020

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.

@p-mongo
Copy link
Collaborator

p-mongo commented Jun 11, 2020

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.

arthurmde added a commit to arthurmde/mongoid-history that referenced this issue Mar 9, 2022
@arthurmde
Copy link

arthurmde commented Mar 9, 2022

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

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

No branches or pull requests

5 participants