Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#import method conflicts #494

Closed
itay-grudev opened this issue Jan 28, 2018 · 10 comments · Fixed by #498
Closed

#import method conflicts #494

itay-grudev opened this issue Jan 28, 2018 · 10 comments · Fixed by #498

Comments

@itay-grudev
Copy link

elasticsearch-rails uses the method import for importing data into ES. And while I am contradicted about which library holds stronger right to the import keyword, would you consider renaming the method to bulk_import or at least create an alias? I believe in general it would be nice to not use such a generic method name for an external library with such a specific function.

@jkowens
Copy link
Collaborator

jkowens commented Jan 29, 2018

@zdennis this seems to be reported enough that I'm wondering if we should consider renaming import to something like bulk_import as suggested and then creating an import alias. What do you think?

@jkowens
Copy link
Collaborator

jkowens commented Jan 29, 2018

Here's a quick stab at an update that should maintain backwards compatibility: master...jkowens:alias_import_method

cc: @zdennis

@itay-grudev
Copy link
Author

That's great. The alias if responds_to? is a quite clever hack. And I'm REALLY impressed by your quick response.

@jkowens
Copy link
Collaborator

jkowens commented Jan 29, 2018

Haha thanks, but I have to credit the Ransack team for that nifty trick. They do something similar with the search method added to ActiveRecord::Base.

@zdennis
Copy link
Owner

zdennis commented Feb 9, 2018

@jkowens, this is great. My only question is should we Use the second argument to ‘respond_to?’ to be extra safe that we aren’t clobbering anything?

@itay-grudev
Copy link
Author

itay-grudev commented Feb 9, 2018

@zdennis This should be alright, as the second argument is for private methods. And even if there is an import method in a private scope, it doesn't concern us. We only care if there is an import method in the public scope in which case we try not to override it.

@jkowens
Copy link
Collaborator

jkowens commented Feb 10, 2018

@zdennis that seems like a good thought to me. We might as well try to avoid clobbering private methods if possible. I’ll go ahead and update the PR.

@jkowens
Copy link
Collaborator

jkowens commented Feb 11, 2018

@zdennis interestingly, making this change reveals that JRuby provides a private import method (our tests failed).

See https://github.com/jruby/jruby/blob/master/core/src/main/ruby/jruby/java/core_ext/module.rb#L54

I'm a bit on the fence now. If we don't create an import alias for apps with ActiveRecord objects that have private import methods, that could lead to surprise failures in existing apps. Although clobbering that method probably isn't the best thing either.

@itay-grudev
Copy link
Author

I believe the best solution is to keep it as is, update the documentation to explicitly recommend using bulk_import and update the tests to use bulk_import so they pass.

Only a very small amount of JRuby people will notice a problem if they are importing modules in their ActiveRecord models.

And you can drop the old import method alias the next time you are doing a major release.

@jkowens
Copy link
Collaborator

jkowens commented Feb 13, 2018

@zdennis I think I'm going to with what I believe @itay-grudev is suggesting and only check the public method scope when adding the import alias. That will most closely match current functionality and not introduce any surprises. We can either add the check for private scope or completely remove the import alias in a future major release. One day we'll have to go all in and release a 1.0 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants