Invalid conditions in a query, error handling and symbols
Repository#read returns an empty array if a query is not valid, I'm not sure if that's the desired behavior. For instance when you have a resource like this:
class User include DataMapper::Resource property :id, Serial property :login, String end User.create(:login => 'john') # then this will return nil User.first(:login => :john)
The case here is that if a query is not valid, then it's an error and I would expect an exception to be thrown instead of an empty result which makes me think there is no "john" in the db rather then I did something wrong.
Another issue is that symbols used to work and in my opinion it was quite convenient.
Comments and changes to this ticket
- Assigned user set to Dan Kubb (dkubb)
- State changed from unconfirmed to accepted
I will think on this. In general we attempt to not throw exceptions except for exceptional cases. Creating a query with invalid data, and attempting to return results doesn't feel like an exceptional circumstance, in fact I would expect it to happen very regularly.
Also there is nowhere in the specification that says Symbol should be treated as a String when querying, so relying on unspecified behavior isn't recommended. There are adapters that would treat String and Symbol differently, and not match a value stored as a String when provided a Symbol in the query, and vice versa. Whether or not that should be part of the spec is open for debate. I'm not against it, but only in very specific cases -- we're already so permissive with the Query syntax that nearly 20% of all the code in dm-core is for DataMapper::Query.
In general we now err on the side of strictness and only relax constraints when a good reason is put forward.