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 error when delete overridden in model #5

Open
james-ai opened this issue Mar 2, 2015 · 5 comments
Open

Comments

@james-ai
Copy link

james-ai commented Mar 2, 2015

I get a wrong number of arguments (1 for 0) error when trying to delete an object. I have overridden the delete method in the model so when someone tries to remove an object a deleted flag is set and the object is left in the database.

Seems the problem happens here https://github.com/haihappen/mongoid-versioning/blob/master/lib/mongoid/core_ext/versioning.rb#L50

Don't suppose you'd have a fix in mind for this, would you?

Thanks,
James.

@ream88
Copy link
Owner

ream88 commented Mar 3, 2015

I will look into it … however I don't know why this is happening, don't think the problem is on my side tbh.
Can you paste your code here?

@james-ai
Copy link
Author

james-ai commented Mar 3, 2015

def delete
  # Remove the fixture from the competitors' fixture list
  competitors.each do |competitor|
    competitor.fixtures.delete(self.id)
  end

  self.update_attributes(deleted: true, deleted_at: Time.zone.now)
end

This is from the logger

E, [2015-03-02T13:59:13.338342 #30496] ERROR -- : wrong number of arguments (1 for 0)
E, [2015-03-02T13:59:13.338393 #30496] ERROR -- : /home/sport/sport/releases/20150302124748/app/models/fixture.rb:49:in `delete'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/relations/embedded/many.rb:136:in `delete'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-versioning-1.0.0/lib/mongoid/core_ext/versioning.rb:50:in `revise'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:427:in `block in make_lambda'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:145:in `call'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:145:in `block in halting_and_conditional'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/interceptable.rb:138:in `run_callbacks'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/persistable/updatable.rb:115:in `prepare_update'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/persistable/updatable.rb:138:in `update_document'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/persistable/savable.rb:25:in `save'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/persistable/savable.rb:44:in `save!'
/home/sport/sport/releases/20150302124748/lib/sports_db_importers/importer.rb:100:in `block in import'
/home/sport/sport/releases/20150302124748/lib/sports_db_importers/importer.rb:61:in `each'
/home/sport/sport/releases/20150302124748/lib/sports_db_importers/importer.rb:61:in `import'
services/sports_db_importer_service.rb:28:in `block in <top (required)>'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:648:in `yield_document'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:123:in `block in each'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:28:in `block in each'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:28:in `each'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/moped-2.0.3/lib/moped/cursor.rb:28:in `each'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/moped-2.0.3/lib/moped/query.rb:77:in `each'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual/mongo.rb:122:in `each'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/mongoid-4.0.1/lib/mongoid/contextual.rb:20:in `each'
services/sports_db_importer_service.rb:24:in `<top (required)>'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/commands/runner.rb:60:in `load'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/commands/runner.rb:60:in `<top (required)>'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in `require'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:90:in `runner'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:45:in `require'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:45:in `block in exec_app_rails'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:34:in `loop'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:34:in `exec_app_rails'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/cli.rb:5:in `<top (required)>'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/bin/rails:9:in `require'
/home/sport/sport/shared/bundle/ruby/2.1.0/gems/railties-4.2.0/bin/rails:9:in `<top (required)>'
/home/sport/sport/shared/bundle/ruby/2.1.0/bin/rails:23:in `load'
/home/sport/sport/shared/bundle/ruby/2.1.0/bin/rails:23:in `<main>'

The process that produces that log output doesn't ever call #delete as far as I can tell though.

@ream88
Copy link
Owner

ream88 commented Mar 3, 2015

Line 49 is competitor.fixtures.delete(self.id)?

@james-ai
Copy link
Author

james-ai commented Mar 3, 2015

Been using delete from Ruby's Array class fine until including mongoid-versioning though. That's why I thought it might be some weird interaction.

@james-ai
Copy link
Author

james-ai commented Mar 4, 2015

Even after changing the code to use delete_if the problem persists.

def delete
  # Remove the fixture from the competitors' fixture list
  competitors.each do |competitor|
    competitor.fixtures.delete_if {|f| f.id == self.id}
  end

  self.update_attributes(deleted: true, deleted_at: Time.zone.now)
end

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