Skip to content

Loading…

ArgumentError: wrong number of arguments (0 for 1) #52

Closed
cam156 opened this Issue · 32 comments

7 participants

@cam156

I just installed mailboxer yesterday and was in an attempting to get it running, so I may be completely off base here.

Here is my code:

u1 = User.where(login:'u1').first
u2 = User.where(login:'u2').first
recipt = u1.send_message(u2, "log", "Audit Run")

User model contains the lines

include Mailboxer::Models::Messageable
class User < ActiveRecord::Base

# set this up as a messageable object
acts_as_messageable

#method needed for messaging
def name
read_attribute :login

end

#method needed for messaging
def mailboxer_email
return nil

end
...
end

When I send a message I get the following error:

ArgumentError: wrong number of arguments (0 for 1)
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/lib/mailboxer/models/messageable.rb:103:in read'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:146:in
attribute_change'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:117:in block in changes'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:117:in
map'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:117:in changes'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/attribute_methods/dirty.rb:34:in
block in save!'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/attribute_methods/dirty.rb:33:in tap'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/attribute_methods/dirty.rb:33:in
save!'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:246:in block in save!'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:295:in
block in with_transaction_returning_status'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in transaction'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:208:in
transaction'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:293:in with_transaction_returning_status'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:246:in
save!'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/app/models/message.rb:54:in block in deliver'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/app/models/message.rb:52:in
each'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/app/models/message.rb:52:in deliver'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/lib/mailboxer/models/messageable.rb:59:in
send_message'
from (irb):5
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in start'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in
start'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/railties-3.2.3/lib/rails/commands.rb:41:in <top (required)>'
from script/rails:6:in
require'

I tracked the error down to the fact the read method in mailboxer-0.6.5/lib/mailboxer/models/messageable.rb was getting called with no arguments by the send method in dirty.

I modified line 103
from
def read(obj)
to
def read(obj=nil)

This allowed the above code to complete successfully. I have no idea what the repercussions are, I was just looking to get the code running.

It seems like the read attribute of the Recipt and the read method of Messageble are getting confused by Active Record and that the wrong one is getting called during the active record save.

I am including some debug output below so you can see what values are being sent. I added some debug here and there to determine where the error was occuring and those are also in this stream.

1.9.3p125 :005 > recipt = u1.send_message(u1, "log", "Audit Run")
!!!!!!!!!!!!!!!!!!!! before conversation
!!!!!!!!!!!!!!!!!!!! after conversation #
!!!!!!!!!!!!!!!!!!!! after message #
Before send #

 message recipt = #<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: false, trashed: false, deleted: false, mailbox_type: "inbox", created_at: nil, updated_at: nil>
 sender recipt = #<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: true, trashed: false, deleted: false, mailbox_type: "sentbox", created_at: nil, updated_at: nil>
~~~~~~~~~~~~~~~~~~~~ dilver 2
~~~~~~~~~~~~~~~~~~~~ dilver3 
~~~~~~~~~~~~~~~~~~~~ dilver4 
#<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: false, trashed: false, deleted: false, mailbox_type: "inbox", created_at: nil, updated_at: nil>
  SQL (0.2ms)  BEGIN
  SQL (10.5ms)  INSERT INTO `conversations` (`created_at`, `subject`, `updated_at`) VALUES (?, ?, ?)  [["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["subject", "Audit Run"], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "subject"
^^^^^^^ attr= "created_at"
^^^^^^^ attr= "updated_at"
^^^^^^^ attr= "id"
  SQL (1.0ms)  INSERT INTO `notifications` (`attachment`, `body`, `conversation_id`, `created_at`, `draft`, `notification_code`, `notified_object_id`, `notified_object_type`, `sender_id`, `sender_type`, `subject`, `type`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["attachment", nil], ["body", "log"], ["conversation_id", 28], ["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["draft", false], ["notification_code", nil], ["notified_object_id", nil], ["notified_object_type", nil], ["sender_id", 6], ["sender_type", "User"], ["subject", "Audit Run"], ["type", "Message"], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "type"
^^^^^^^ attr= "sender_id"
^^^^^^^ attr= "sender_type"
^^^^^^^ attr= "body"
^^^^^^^ attr= "subject"
^^^^^^^ attr= "attachment"
^^^^^^^ attr= "conversation_id"
^^^^^^^ attr= "created_at"
^^^^^^^ attr= "updated_at"
^^^^^^^ attr= "id"
  SQL (1.6ms)  INSERT INTO `receipts` (`created_at`, `deleted`, `mailbox_type`, `notification_id`, `read`, `receiver_id`, `receiver_type`, `trashed`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)  [["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["deleted", false], ["mailbox_type", "inbox"], ["notification_id", 28], ["read", false], ["receiver_id", 6], ["receiver_type", "User"], ["trashed", false], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "receiver_id"
^^^^^^^ attr= "receiver_type"
^^^^^^^ attr= "mailbox_type"
^^^^^^^ attr= "notification_id"
^^^^^^^ attr= "created_at"
^^^^^^^ attr= "updated_at"
^^^^^^^ attr= "id"
   (4.3ms)  COMMIT
#<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: true, trashed: false, deleted: false, mailbox_type: "sentbox", created_at: nil, updated_at: nil>
  SQL (1.8ms)  BEGIN
  SQL (1.1ms)  INSERT INTO `receipts` (`created_at`, `deleted`, `mailbox_type`, `notification_id`, `read`, `receiver_id`, `receiver_type`, `trashed`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)  [["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["deleted", false], ["mailbox_type", "sentbox"], ["notification_id", 28], ["read", true], ["receiver_id", 6], ["receiver_type", "User"], ["trashed", false], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "read"
   (1.6ms)  ROLLBACK

@cam156 cam156 added a commit to psu-stewardship/mailboxer that referenced this issue
@cam156 cam156 changed to avoid the error: 'ArgumentError: wrong number of arguments…
… (0 for 1)' refs #52
d8a40ae
@Roendal

Hi @cam156!

Can you do exactly the same on rails 3.0 and rails 3.2.2 without your fix to see if it is related with rails 3.2.3?

@cam156
@Roendal

It's the first time I see this bug and I can't do any testing right now with rails :(

Have you tested the sample app to see if it also crashes in the same way?

Your fix its ok to solve it right here, right now, but not understanding where it cames from can lead to a major crash in somtime. @atd, does this bug make any sense to you?

@atd

Hi @cam156

Could you write an spec that exposes the bug?

@cam156
@Roendal

Don't worry for rails 3.0 ;)

Test the sample and if the problem persits, try to write a spec.

@cam156
@cam156
@cam156
@cam156

I retracted the last update, as I realized I was still pointing to my Fork, not the local copy when it was working.

I also tried coping one of your models (Duck) from your app to mine, and got the same error so it does not see to be related to the model definition.

@atd

It is hard for us to debug a relative big application, if we do not know it. Specially if there are other gems implied.

It would be of great help if the spec could be written in a fork of mailboxer repository

@cam156
@atd

Maybe, you can try removing all the other gems and see if the spec you wrote still fails.

Then, adding them until you find the guilty one.

@Roendal

It seems related to a gem calling .read for an object, maybe that helps.

@cam156

Ok I was able to track it down to hydrahead. In the Hydrahead initializer the following line is executed:
User.send(:include, Hydra::GenericUserAttributes)

Here is a reference for the Hydra class: http://rubydoc.info/github/projecthydra/hydra-head/Hydra/GenericUserAttributes

When the above is removed from the initializer the error is also removed. Any ideas on why this mixin is causing an issue?

Would you want me to make the mailbox, hydra code available on a branch in my mailboxer fork?

@atd

It is strange, because the method that seems to be redefined is read and there is not any code about read in that module Hydra::GenericUserAttributes

Yes, please @cam156, could you provide us with a branch of mailboxer that includes the hydra code and fails the specs?

@cam156
@atd

@cam156 I think that psu-stewardship@d8a40ae#diff-0 will probably hide a bug. If there is a method that is overwriting mailboxer's read, that functionality, mark an object as read in your application, won't probably work

@cam156
@atd

@cam156 if you create https://github.com/psu-stewardship/mailboxer/tree/WHYDRA with your patches, and specs fail, don't you think your patches are wrong?

@cam156
@atd

This is what I understood from #52 (comment)

Here is a link to the combined hydra mailboxer: https://github.com/psu-stewardship/mailboxer/tree/WHYDRA

Just run the mailboxer specs and you will see the failures. The first one I get is at: ./spec/integration/message_and_receipt_spec.rb:25

Anyway, we think we have found the issue. It is related to ActiveRecord::DangerousAttributeError http://api.rubyonrails.org/classes/ActiveRecord/DangerousAttributeError.html

We are working on it at https://github.com/ging/mailboxer/tree/issue-52

Thank you for your perseverance.

@cam156
@daveworth

I retract all of that as I misread the original question. I'm sorry :-/

@rafaelgg

FYI we have a setup using social_stream that has this very problem. Let me know if you need any more info in order to debug it. For now we'll be using the 'issue-52' branch. Any chance this is merged upstream?

@atd

The issue is that read is a reserved word in ActiveRecord, but also a column in Mailboxer's receipts table. So what is missing is a migration that changes that column name, and fixing things in code too

@rafaelgg

That's right. In our case @notification.is_unread?(@actor) was trying:

https://github.com/ging/mailboxer/blob/master/lib/mailboxer/models/messageable.rb#L99

Rather than receipt.read

@rafaelgg

Please don't merge the issue-52 upstream. Our setup makes the ruby interpreter crash when using this branch (!!!).

We need to get this working. Let me know if I can help fixing this issue properly.

@atd

The work in that branch is not finished yet. Steps missing:

  1. Create a migration that changes the read field for any other word
  2. Fixing the code

@Roendal commented he would take the job when he had some time, so he can say if help is needed. If it is for me, go ahead!

@Roendal

I will really love to give it a try, but right now is nearly impossible. And works seems just to grow by seconds.

I will talk with @rafaelgg in person to discuss about this.

Thanks guys :(

@ftufek

I had a similar problem with ArgumentError, my problem was that I had another model named Message inside my rails app. Removing that model from the app solved the problem.

Maybe there's something similar going on here too, hope this helps.

@searsaw

I believe this has been solved. The method and column names have been changed. Also, the namespacing of the models has been completed.

@searsaw searsaw closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.