Skip to content

Conversation

@durran
Copy link
Member

@durran durran commented Jun 6, 2012

The introduction of commit 078354a breaks any application that would attempt to flatten an array of object ids, forcing it to appear hung and never exiting (and really hard to debug for those who don't have a good knowledge of Ruby's core API). Since we do this in Mongoid, and I'm sure many others do, release 1.6.3 is unusable.

The proper implementation of this would be to return nil from BSON::ObjectId#to_ary in order to allow proper flattening as well as allowing for Kernel.Array to work properly. However BSON::ObjectId does not follow Ruby conventions with respect to BSON::ObjectId#to_a either, which returns the internal data instead of the object id wrapped in an array.

I was about to re-implement BSON::ObjectId#to_a as well, however this has repercussions as there are current expectations around what BSON::ObjectId#to_a returns in the driver albeit incorrect. So this pull is simply to get the driver back to a reusable state with tests around Array#flatten and Array#flatten! to ensure this isn't broken again.

There needs to be an overhaul of this class with regards to core Ruby APIs and what they are expected to return, as simple changes like this have rippling affects. BSON::ObjectId#to_a needs to change to adhere to this, but it's going to break other things as well. IMO it's best to stay with the existing functionality to not be breaking apps in patch releases.

- The introduction of the previous implementation breaks any attempt
  to flatten an array of object ids.
@TylerBrock
Copy link
Contributor

OK, thank you Durran. Expect 1.6.4 to resolve this issue shortly.

TylerBrock added a commit that referenced this pull request Jun 6, 2012
@TylerBrock TylerBrock merged commit 976fb36 into mongodb:master Jun 6, 2012
@durran
Copy link
Member Author

durran commented Jun 6, 2012

Thank you sir!

@durran
Copy link
Member Author

durran commented Jun 6, 2012

Note that you can see in the ruby specs themselves, they are expecting #to_ary to return nil in order to work for flatten behavior:

https://github.com/rubyspec/rubyspec/blob/master/core/array/flatten_spec.rb#L106

Also Aaron Patterson wrote a good blog post on this a while back:

http://tenderlovemaking.com/2011/06/28/til-its-ok-to-return-nil-from-to_ary/

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

Successfully merging this pull request may close these issues.

2 participants