Skip to content

Conversation

@midnight-wonderer
Copy link
Contributor

Hello,
As I mentioned on #2430, we use insert_many with an enumerable instead of an array; we want to make sure it will continue to work into the future.

It would be great if you guys could include this test.
I am happy to adjust the pull request as you see fit.

@alexbevi
Copy link
Contributor

Hi @midnight-wonderer, and thanks for submitting this PR! We will review this and get back to you with any feedback.

@midnight-wonderer
Copy link
Contributor Author

It already breaks D: (test failed)
Let me see how I can help with the situation; I'll get back to you shortly.

@midnight-wonderer
Copy link
Contributor Author

Updated!
The breaking change was introduced in commit#5931b9 by @neilshweky (pinging to request a code review).
The updated commit should still comply with RUBY-2976.

The user should be responsible for side effects that may occur because of multiple each iterations from the driver. It is the power of duck-typing, and also, it is undocumented, after all.

I would like to suggest subclassing ArgumentError so people can confidently rescue from the error; submitting an empty operation to bulk_write has a valid use case, IMO, but probably another time (not in this PR).

@neilshweky
Copy link
Contributor

Hey @midnight-wonderer thanks for the ping! I just added another test, and some docs stating that we now support enumerables in the respective methods. Would you mind taking a look at that?

@neilshweky neilshweky requested review from comandeo, neilshweky and p-mongo and removed request for neilshweky August 18, 2022 22:07
@midnight-wonderer
Copy link
Contributor Author

LGTM (Neil's commit)

- When 0 is given as the max connection pool size, it is now interpreted to
mean no limit.
- The default maximum connection pool size has been increased to 20 from 5.
- Added support for enumerables in bulk write operations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are fixing this let's backport the fix to 2.18-stable and then it won't need a release note here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why won't it need a release not even if we're backporting to 2.18?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the break was in 2.18, thus after the fix there wouldn't be any stable branch where the issue exists so it might be confusing to people to try to work out which versions are broken.

But if you wish to have the note, that's fine, I would just phrase it as "Reinstated support for enumerables" or similar since it was already present and unintentionally broken.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh okay I will remove it

# collection.insert_many([{ name: 'test' }])
#
# @param [ Array<Hash> ] documents The documents to insert.
# @param [ Array<Hash>, Enumerable ] documents The documents to insert.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @param [ Array<Hash>, Enumerable ] documents The documents to insert.
# @param [ Array<Hash>, Enumerable<Hash> ] documents The documents to insert.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be correct yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use type in Ruby, so I don't know which one can be generic.
However, if Enumerable can be generic too and Array is also an Enumerable, we can also just do Enumerable<Hash>.

There are three possibilities forward:

  • Array<Hash>, Enumerable as Neil suggested
    probably maybe because Enumerable is not a generic type? And also not to confuse developers that are new to the concept of Ruby's module.
  • Array<Hash>, Enumerable<Hash> as you suggested
    because Enumerable is actually a generic type; leaving the Array type as is for the same reason as above.
  • Enumerable<Hash>
    if Enumerable is a generic type, and we prioritize conciseness.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on this, I had just looked for examples elsewhere in the code base and this is what we did. I don't mind switching it...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Array<Hash> | Enumerable<Hash> is redundant, my vote is for Enumerable<Hash> only.

@midnight-wonderer This notation simply signifies the expected type of values in the container, we haven't magically come up with a way to add generics to Ruby :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine with me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@midnight-wonderer
Copy link
Contributor Author

I resolved the spec description issue mentioned by p-mongo, hope you don't mind; could you take a look at the other comments? @neilshweky

@neilshweky neilshweky requested a review from p-mongo August 26, 2022 19:27
@neilshweky
Copy link
Contributor

@p-mongo this is rfal

@p-mongo p-mongo changed the title RUBY-3087 add a test for insert_many with enumerable inputs RUBY-3087 reinstate ability to call insert_many with Enumerable inputs which are not Array instances Aug 28, 2022
@p-mongo
Copy link
Contributor

p-mongo commented Aug 28, 2022

@midnight-wonderer Thank you again for the PR and the fix.

@p-mongo p-mongo merged commit 6bf442e into mongodb:master Aug 28, 2022
p-mongo pushed a commit that referenced this pull request Aug 28, 2022
…s which are not Array instances (#2594)

* RUBY-3087 add a test for insert_many with enumerable inputs

* RUBY-3087 raise exception on bulk_write without using an Array method

* RUBY-3087 add test, docs

* add docs, release notes

* Fix the description of empty bulk_write spec to match the behavior

* Update docs/release-notes.txt

* change docstrings to use enumerables

Co-authored-by: Neil Shweky <neilshweky@gmail.com>
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.

4 participants