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

Resolve deprecation warning in preparation for Rails 6 (eventually) #4624

Open
jywarren opened this issue Jan 15, 2019 · 6 comments
Open

Resolve deprecation warning in preparation for Rails 6 (eventually) #4624

jywarren opened this issue Jan 15, 2019 · 6 comments
Labels
fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet help wanted requires help by anyone willing to contribute refactorization Ruby

Comments

@jywarren
Copy link
Member

jywarren commented Jan 15, 2019

Travis reports this warning several times:

DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "COUNT(term_data.tid) DESC". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). (called from block in related at /app/app/models/tag.rb:328)

I believe we should wrap term_data.tid as recommended, like Arel.sql(term_data.tid) but am not 100% sure. This should make our test reports much more readable!

https://travis-ci.org/publiclab/plots2/builds/479677570#L3230

The line change should be here, i guess:

.order('COUNT(term_data.tid) DESC')

@jywarren jywarren added help wanted requires help by anyone willing to contribute Ruby refactorization fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet labels Jan 15, 2019
@jywarren
Copy link
Member Author

This has been marked as a good candidate for becoming a first-timers-only issue like these, meaning that it's simple, self-contained, and with some extra formatting, could be a great entry point for a new contributor. If you're familiar enough with this code, please consider reformatting or reposting it as a first-timers-only issue, and then ping @publiclab/reviewers to get it labelled. Or, if this is not your first time, try to solve it yourself!

@IshaGupta18
Copy link
Collaborator

Okay @jywarren so the deprecation warning has changed I think (atleast at my local machine) to this:

DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "created ". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). (called from tagNearbyNodes at /home/isha/plots2/app/services/search_service.rb:136)

Also, the line 328 has now been changes to this:

.order(count: :desc)

So I think we should probably address this new warning now, if I am correct. What do you think?

@IshaGupta18
Copy link
Collaborator

IshaGupta18 commented Feb 2, 2019

Okay so changing this line:

items.order("created #{order_direction}")

to this:
items.order("created #{Arel.sql(order_direction)}")
gives these errors:

ERROR["test_running_search_taglocations_with_valid_params", #<Minitest::Reporters::Suite:0x0000561e3d5ab9d0 @name="SearchServiceTest">, 71.05786943600106]
 test_running_search_taglocations_with_valid_params#SearchServiceTest (71.06s)
TypeError:         TypeError: no implicit conversion of nil into String
            app/services/search_service.rb:136:in `tagNearbyNodes'
            test/unit/api/search_service_test.rb:67:in `block in <class:SearchServiceTest>'

ERROR["test_running_search_taglocations_with_valid_params_and_specific_period", #<Minitest::Reporters::Suite:0x0000561e3d529980 @name="SearchServiceTest">, 71.07244423100201]
 test_running_search_taglocations_with_valid_params_and_specific_period#SearchServiceTest (71.07s)
TypeError:         TypeError: no implicit conversion of nil into String
            app/services/search_service.rb:136:in `tagNearbyNodes'
            test/unit/api/search_service_test.rb:75:in `block in <class:SearchServiceTest>'

What do you think should be done?

@snpd25
Copy link
Contributor

snpd25 commented Feb 13, 2019

@IshaGupta18 What if we change the line 328 in tag.rb from:
.order(count: :desc)
to:
.order(Arel.sql('COUNT(term_data.tid) DESC'))

@IshaGupta18
Copy link
Collaborator

I am so sorry @snpd25 I missed your comment, let me have a look at it ASAP.

@IshaGupta18
Copy link
Collaborator

I think that issue was probably resolved, could you have a look the Deprecation warning I have posted in #4624 (comment) ? Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet help wanted requires help by anyone willing to contribute refactorization Ruby
Projects
None yet
Development

No branches or pull requests

3 participants