# net::LDAP and can't dump singleton method

**URL:** <https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799>\
**Category:** Rails\
**Created:** [October 3, 2006, 3:02am UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799 "2006-10-03T03:02:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 3, 2006, 3:02am UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/1 "2006-10-03T03:02:26Z")

</div>

What does this mean and how do I fix it? It makes my server hang with a  
500 error.

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 3, 2006, 6:12am UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/2 "2006-10-03T06:12:36Z")

</div>

On 10/2/06, bluengreen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What does this mean and how do I fix it? It makes my server hang with a  
> 500 error.

A full backtrace would be useful.

Chances are, you’re trying to do something that tries to Marshal a  
Net::LDAP object, and that can’t be marshaled because it’s got a  
singleton method on it (that is, the object’s singleton class has a  
method, and if you don’t understand that – I suggest you look up  
singleton class, metaclass, and eigenclass in the context of Ruby).

Have you got your Net::LDAP operation modified and/or in a transaction?

## -austin

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 3, 2006, 3:53pm UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/3 "2006-10-03T15:53:47Z")

</div>

You are correct about all those things. That is exactly what I’m  
doing. I have my Net::LDAP stuff inside of my ActiveRecord model for  
users. It’s within a login method. Here is what I’m trying to do,

def self.login(username, password)  
begin  
ldap = Net::LDAP.new  
ldap.host = “gonzo”  
ldap.port = 389

```
  result = ldap.bind_as(
    :base => "dc=net",
    :filter => "(cn=#{username})",
    :password => password
  )

rescue => e
      false
end
   result.first

```

end

And then use it like:

session[:user] = AuthUser.login(params[:user][“username”],  
params[:user][“password”])

I’ve tried a million differnt ways. I can get it to work if all I  
return from the method is true or false. If I try return any attributes  
from the LDAP object it dumps errors on me.

It errors out when I try it outside of AR as well.

I just don’t know how would you go about saving the attribute values  
into the session? Are they always tied to the object? Is there any way  
to copy the values only?

Thanks in advance,  
Phill

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 3, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/4 "2006-10-03T17:44:02Z")

</div>

On 10/3/06, bluengreen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You are correct about all those things. That is exactly what I’m  
> doing. I have my Net::LDAP stuff inside of my ActiveRecord model for  
> users. It’s within a login method. Here is what I’m trying to do,

…Unfortunately, I don’t really do much with Rails or Net::LDAP.  
Hopefully others can help with that, but the dump message is a pure  
Ruby issue related to trying to Marshal a singleton value.

This means you can’t put the actual auth result in the session (I’m  
assuming it’s a Marshaled object); you will have to somehow get the  
data out of the auth result and use those in the session. You may want  
to try to write a little Ruby program that tries your auth without  
Rails and get help about that from the Net::LDAP homepage.

## -austin

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 3, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/5 "2006-10-03T17:47:11Z")

</div>

Austin Z. wrote:

> On 10/2/06, bluengreen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > What does this mean and how do I fix it? It makes my server hang with a  
> > 500 error.
> 
> A full backtrace would be useful.
> 
> Chances are, you’re trying to do something that tries to Marshal a  
> Net::LDAP object, and that can’t be marshaled because it’s got a  
> singleton method on it (that is, the object’s singleton class has a  
> method, and if you don’t understand that – I suggest you look up  
> singleton class, metaclass, and eigenclass in the context of Ruby).
> 
> Have you got your Net::LDAP operation modified and/or in a transaction?
> 
> ## -austin
> 
> Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
> \* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
> \* removed\_email\_address@domain.invalid

Austin, you’re right. The Net::LDAP::Entry class has some stuff that  
can’t be marshalled. (For one thing, there was a hash that took a  
closure.) However, I changed this stuff recently so there should be no  
problem marshalling entries. Look in entry.rb in the Net::LDAP distro  
for commentary.

Bluengreen, if you’d be so kind as to sync to the latest Net::LDAP  
source code and try again, I’d appreciate it. I think your problem is  
fixed but it would be very helpful if you can confirm or deny.

There’s enough new stuff in Net::LDAP (performance improvements, LDIF  
support) that it’s time for a new release anyway.

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 4, 2006, 4:16pm UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/6 "2006-10-04T16:16:41Z")

</div>

bluengreen wrote:

> How do I sync with the source code? I have version 0.0.4 now. Is there  
> a svn repository?
> 
> Thanks,  
> Phill

Yes, the source is on Rubyforge. There are instructions there on how to  
work with SVN anonymously. If you can’t figure it out, send me a private  
email and I’ll send you a gem.

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 4, 2006, 5:39am UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/7 "2006-10-04T05:39:29Z")

</div>

How do I sync with the source code? I have version 0.0.4 now. Is there  
a svn repository?

Thanks,  
Phill

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 5, 2006, 4:11am UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/8 "2006-10-05T04:11:41Z")

</div>

Francis Thanks. I got the newest code. I got it to work. But I had to  
convert it to an array to get it to my session variable:

result.first.to\_a

Other wise I still get the dump error.

I dunno. Is this how it should work? Or should I just be able to pass  
the entry to my session?

I get to the vars like this in my views and code…

session[:user][0][:dn]  
session[:user][0][:cn]

etc…

It seems a little obtuse. But I’m still pretty green at Ruby.

Thanks,  
Phill

---

<div class="post-metadata">

**Author:** ![bluengreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bluengreen](https://www.ruby-forum.com/u/bluengreen)\
**Post date:** [October 5, 2006, 4:59am UTC](https://www.ruby-forum.com/t/net-ldap-and-cant-dump-singleton-method/70799/9 "2006-10-05T04:59:34Z")

</div>

bluengreen wrote:

> Francis Thanks. I got the newest code. I got it to work. But I had to  
> convert it to an array to get it to my session variable:
> 
> result.first.to\_a
> 
> Other wise I still get the dump error.
> 
> I dunno. Is this how it should work? Or should I just be able to pass  
> the entry to my session?
> 
> I get to the vars like this in my views and code…
> 
> session[:user][0][:dn]  
> session[:user][0][:cn]
> 
> etc…
> 
> It seems a little obtuse. But I’m still pretty green at Ruby.
> 
> Thanks,  
> Phill

I have to guess at this because I can’t see your code, but I think  
you’re taking the return value from a call to Net::LDAP#search, which is  
an array of Net::LDAP::Entry objects, and trying to stuff the result  
into a Rails session. And of course the session barks because it can’t  
persist the object. If you’re sure you’ve installed the latest code and  
Rails is seeing the latest, then you should look at the error backtrace  
to see if Rails is trying to call Net::LDAP::Entry’s custom \_load and  
\_dump methods. (If you installed Net::LDAP 0.0.4 as a gem, then try  
uninstalling the gem, because otherwise Rails might not be loading the  
version of Net::LDAP you think it is.)

If you really can’t get past this, then there are alternative  
approaches, but I really think this should work without any weird hacks.
