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

where raises ArgumentError on unsupported argument types #21944

Merged
merged 1 commit into from Oct 16, 2015

Conversation

Projects
None yet
7 participants
@jwworth
Contributor

jwworth commented Oct 13, 2015

This addresses the following issue:

'where doesn't warn for wrong values'
#20473

@rails-bot

This comment has been minimized.

rails-bot commented Oct 13, 2015

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @chancancode (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@senny

View changes

activerecord/lib/active_record/relation/query_methods.rb Outdated
@@ -551,6 +551,8 @@ def where(opts = :chain, *rest)
WhereChain.new(spawn)
elsif opts.blank?
self
elsif opts.is_a?(Numeric)
raise ArgumentError, 'wrong argument type (Numeric)'

This comment has been minimized.

@senny

senny Oct 13, 2015

Member

would be nice to also include the number in the error message.

This comment has been minimized.

@jwworth

jwworth Oct 13, 2015

Contributor

@senny makes sense; adding that change.

@chancancode

This comment has been minimized.

Member

chancancode commented Oct 14, 2015

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 14, 2015

I don't think that we should special case Numeric, we should raise on anything that we don't explicitly support.

r? me <--- I guess the bot isn't smart enough to handle that...

@sgrif sgrif assigned sgrif and unassigned rafaelfranca Oct 14, 2015

@jwworth

This comment has been minimized.

Contributor

jwworth commented Oct 15, 2015

@sgrif I think the things we support here are Strings, Hashes, Arrays, and objects that respond to to_h, per:

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/forbidden_attributes_protection.rb#L22

Does that make sense?

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 15, 2015

sounds right

@jwworth

This comment has been minimized.

Contributor

jwworth commented Oct 15, 2015

@sgrif that makes sense; updated PR to raise unless argument is a supported type

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 15, 2015

Cool. Can you squash?

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 15, 2015

And also add a CHANGELOG entry

@jwworth

This comment has been minimized.

Contributor

jwworth commented Oct 16, 2015

@sgrif squashed with a CHANGELOG entry.

@jwworth jwworth changed the title from where raises ArgumentError on Numeric arguments to where raises ArgumentError on unsupported argument types Oct 16, 2015

@matthewd

This comment has been minimized.

Member

matthewd commented Oct 16, 2015

It feels like this should be the job of the where clause factory to me ¯_(ツ)_/¯

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 16, 2015

Good point. I'll move it in a few

sgrif added a commit that referenced this pull request Oct 16, 2015

Merge pull request #21944 from jwworth/issue-20473
where raises ArgumentError on unsupported argument types

@sgrif sgrif merged commit cd4575f into rails:master Oct 16, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jwworth

This comment has been minimized.

Contributor

jwworth commented Oct 16, 2015

@sgrif @matthewd Agreed. I can handle this today with another pull request, if you'd like

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 16, 2015

All good, thanks. :)

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