#917 ✓resolved
Piotr Solnica (solnic)

Invalid conditions in a query, error handling and symbols

Reported by Piotr Solnica (solnic) | June 21st, 2009 @ 08:37 AM | in 0.10.0

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

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 21st, 2009 @ 09:57 PM

    • 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.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 23rd, 2009 @ 12:34 AM

    • State changed from “accepted” to “resolved”

    (from [e48baef0e79aad54c96f5e2a73c5d196eefe8326]) Updated Query conditions to typecast values

    [#917 state:resolved] [#918 state:resolved] http://github.com/datamapper/dm-core/commit/e48baef0e79aad54c96f5e2...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Referenced by

Pages