On 15.04.2011 23:31, Michael Koziarski wrote:

It doesn't have backwards compatibility in terms of the values
returned to a user, however it would have significantly difference
Currently the values returned are already non-deterministic except if you have a default scope with ordering. This is because most (all?) databases don't guarantee a specific result ordering without an order clause. If backwards compatibilty is an issue here, we could just emit a warning instead of raising. Start raising in rails 3.1.

performance characteristics. Removing the limit will make the
database examine multiple rows, lots of them in your case, which won't
be ideal.
You are right - but this would only happen once, because we'd then get an exception and fix the bug. Otherwise the bug might never be noticed.

Adding a limit 1 clause does not guarantee good performance. Just take a "select * from users order by random() limit 1". This can be *very slow* if users has many rows because the whole set gets ordered before only a single result is returned.

If you are really concerned about performance (it should never be a problem once there are no bugs/ bad designs left), just replace the LIMIT 1 with a LIMIT 2. As soon as we get > 1 rows we can still raise.

The dynamic finders are currently a small piece of syntactic sugar for
'where x = ? limit 1', I'm not sure that changing them to do something
more complete really gains us much.
As explained in my first post I think there are huge gains in terms making users aware of design flaws in their code and so preventing them from potential security issues in their apps.

An easier fix for your case would be a unique index, and a model
method which raises ArgmentError when passed null.

Sure, but this will only help in this particular case and not reveal other cases which might still present somewhere.

I'd be happy to provide a patch. I expect it to be only 2-3 lines of code.

Corin

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to