#185 ✓resolved
Camilo Lopez

including Comparable in class Class breaks Test::Unit and probably more --committed

Reported by Camilo Lopez | March 19th, 2008 @ 04:47 PM


Opens Class and includes comparable, then overwrites the <=> operators for classes.

Test::Unit::Runner (and very likely more libraries) expects the default behavior from <=> when comparing classes (that is: B < A is true when B is a children of A)

Comments and changes to this ticket

  • Carl

    Carl March 20th, 2008 @ 08:44 AM

    Yeah, please don't mess with class Class. It's worse than messing with Texas!

    It's very bad practice and it breaks a bunch of things. Test::Unit is broken because of this hack.

  • webmat
  • webmat
  • Carl

    Carl March 25th, 2008 @ 03:58 PM

    My comment sounded so arsh. I didn't mean to, really. I -LOVE- DM. Keep up the good work :)

  • Lindsay Holmwood

    Lindsay Holmwood April 2nd, 2008 @ 11:07 PM

    +1. this hit me pretty hard. :-)

  • Mark Bates

    Mark Bates April 9th, 2008 @ 09:52 AM

    This one has completely stopped me dead in my tracks. The only thing I can do is revert to 0.2.5, but since I'm trying to use migrations, that's not really an issue. I can't run my tests, which means my development is now basically at a stand still.

    Adding a method onto Class is fine, but doing something like implementing Comparable on it, is just WAY too much.

    Any ideas when this will be fixed? Does anybody have any good work arounds?

  • Carl

    Carl April 9th, 2008 @ 10:03 AM

    We've also had to revert to 0.2.5. We don't have a workaround; it screws things pretty badly!

    Quite frankly, I'm not even sure it's a good idea to add things directly to Class. They should just mixin a module on each of the class imo. Much cleaner and won't break other code.

    Actually, now that I think about it, that might be the workaround we're looking for. Remove Comparable and <=> from Class and mix it in all the DM classes.

    I'd also like to have an idea of when this will be fixed so we can plan around that.

  • Mark Bates

    Mark Bates April 9th, 2008 @ 10:08 AM

    I've done pretty much what you've said, I've hacked the gem to remove the Class stuff, and I've mixed in Comparable into DataMapper::Base. Of course, I don't know what kind of functionality I've broken in DataMapper, but all my stuff seems to work just fine.

    I don't quite understand why they can't issue a 0.3.1 gem that fixes this issue. This bug ticket has been open for 3 weeks now, it really makes 0.3.0 unusable, which is a shame because otherwise it's a really good release.

  • Carl

    Carl April 9th, 2008 @ 10:11 AM

    It makes it impossible for the community to test for other bugs, too.

    Can you archive your hacked files and let us download them? I'd like to give it a shot too.

  • Mark Bates

    Mark Bates April 9th, 2008 @ 10:25 AM

    Here you go. I've commented out the bottom of typed_set.rb and put include in base.rb. The tests blow up, obviously. I haven't spent anytime trying to get them to pass. If someone does get them to work, and we have a decent patch on our hands, we should give it back to Sam so he can put out an 'official' patch. Use at your own risk.

  • Carl

    Carl April 9th, 2008 @ 10:26 AM

    Your disclaimer definitely sounds scary! ;-)

    Let us know if you run into problems with your hack. We'll likely give it a shot next week.

  • Mark Bates

    Mark Bates April 9th, 2008 @ 08:26 PM

    So I've sucked down the 0.3.0 source from SVN. When I try and run the tests, without any modification, I get the following errors:


    'DataMapper::Adapters::Sql::Mappings::Schema should return all tables from the database schema' FAILED

    expected: 16,

    got: 22 (using ==)



    'DataMapper::Support::Serialization should serialize to YAML' FAILED

    expected: "--- \nid: 1\nname: Frog\nnotes: I am a Frog!\nnice: false",

    got: "--- \nid: 1\nname: Frog\nnotes: I am a Frog!\nnice:" (using ==)



    'DataMapper::Support::Serialization should serialize to XML' FAILED

    expected: "

    got: "



    'DataMapper::Support::Serialization should serialize to JSON' FAILED

    expected: "{ \"id\": 1, \"name\": \"Frog\", \"notes\": \"I am a Frog!\", \"nice\": false }",

    got: "{ \"id\": 1, \"name\": \"Frog\", \"notes\": \"I am a Frog!\", \"nice\": null }" (using ==)


    With that in mind I removed just the include Comparable line from Class. And I get the exact same test errors at the end. So I assume that my change is alright.

    I've zipped up a gem (, so all people should need to do is unzip and install it, and they should be off to the races. Again, use at your own risks, but since the tests pass, I'm hoping there shouldn't be much risk at all.

    Sam, if you're listening, would it possible for you to release this as an official patch?

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 14th, 2008 @ 05:21 PM

    • Milestone cleared.
    • State changed from “new” to “open”
  • Carl

    Carl April 25th, 2008 @ 12:26 AM

    Has this been fixed? 0.3 is out and even though this ticket was to be fixed in 0.3, there's no mention of it being closed anywhere.

  • Mark Bates

    Mark Bates April 25th, 2008 @ 07:25 AM

    Nope. 0.3.0 actually introduced the bug. 0.3.1 is now out an the bug is still there. I had to patch it on every machine we're using. Its a real pain on the butt.

  • kwatch

    kwatch April 26th, 2008 @ 02:42 AM

    I installed 0.3.1 and also got the same error.

    When will you fix it?

  • Sam Smoot

    Sam Smoot April 27th, 2008 @ 09:00 PM

    • Assigned user set to “Sam Smoot”

    If someone wants to give me a patch I can apply cleanly against 0.3.1, I'll apply it and release 0.3.2.

  • Mark Bates

    Mark Bates April 27th, 2008 @ 09:21 PM

    Sam, I've been running with a patched version of 0.3.x for a while now, and it seems to work just fine. The patch is very simple, all you have to do is comment out the include Comparable in Class in typed_set.rb and you should be all set.

    Thanks for trying to get this into 0.3.2. Any ideas when that'll be?

  • Sam Smoot

    Sam Smoot April 28th, 2008 @ 12:53 PM

    • Assigned user changed from “Sam Smoot” to “Adam French”

    I'll get one of my guys on it today. So soon. :)

  • Sam Smoot

    Sam Smoot April 28th, 2008 @ 12:54 PM

    Adam, please try to squeeze this in today, and verify that the specs pass after making the update.

  • Carl
  • Adam French

    Adam French April 28th, 2008 @ 05:22 PM

    /me spending time on getting this fixed right now. will post after I commit something

  • Adam French
  • Adam French

    Adam French April 28th, 2008 @ 05:42 PM

    • Assigned user changed from “Adam French” to “Sam Smoot”
  • Adam French

    Adam French April 28th, 2008 @ 05:42 PM

    • Title changed from “including Comparable in class Class breaks Test::Unit and probably more” to “including Comparable in class Class breaks Test::Unit and probably more --committed”
  • Mark Bates

    Mark Bates April 28th, 2008 @ 07:25 PM

    Sweet! Is there a timeframe for 0.3.2? I can't wait!

  • Carl

    Carl April 29th, 2008 @ 10:26 AM

    This is the best news in ages! Thanks so much for fixing this guys, we'll be able to kiss 0.2.5 goodbye!

  • Sam Smoot

    Sam Smoot May 2nd, 2008 @ 04:20 AM

    • State changed from “open” to “resolved”

    In case you guys didn't see it, DM0.3.2 is out. So calling this one resolved.

    FYI, I encourage anyone who feels a bit brave to give DM 0.9.0 a try. habtm is currently missing (hope to have that this weekend), but other than that, it's much faster, has some spiffy new features and syntax, and overall is a lot less painful than DM 0.2x was.

    I don't remember the number of the old exactly, but I'm guessing the new DM projects probably have at least 3X the number specs as the old, so it's good stuff...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket



Referenced by