[sqlalchemy] InvalidRequestError: get() can only be used against a single mapped class.

2011-12-28 Thread Kent

Was it your intention to no longer allow this type of query().get()?

session.query(cls.orderid).get(orderid)

I get InvalidRequestError: get() can only be used against a single 
mapped class. but the wording is such that I'm not sure you intended to 
limit that use case (there is only a single mapped class in that query).


I'll change such queries, just wanted to bring it up to see if you 
intended it that way.


(Admittedly, if I recall correctly, when I first added it, I think I was 
slightly surprised it worked as I expected...)


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] InvalidRequestError: get() can only be used against a single mapped class.

2011-12-28 Thread Michael Bayer

On Dec 28, 2011, at 11:34 AM, Kent wrote:

 Was it your intention to no longer allow this type of query().get()?
 
 session.query(cls.orderid).get(orderid)

it was !   yes.


 
 I get InvalidRequestError: get() can only be used against a single mapped 
 class. but the wording is such that I'm not sure you intended to limit that 
 use case (there is only a single mapped class in that query).

From the POV of that message there's just a Column, and no mapped class, 
actually being passed.  I knew this wouldn't necessarily be very clear but 
there was no better message I could think of.

 
 I'll change such queries, just wanted to bring it up to see if you intended 
 it that way.
 
 (Admittedly, if I recall correctly, when I first added it, I think I was 
 slightly surprised it worked as I expected...)

amazingly it took me just one second to find the originating issue, which was 
that the identity map was still being searched, thereby causing the wrong 
result:

http://www.sqlalchemy.org/trac/ticket/2144

When something is used in a way I didn't anticipate, my first instinct is often 
to first make that unanticipated case raise an error.   That means it's covered 
and people won't do it.   Later, if we decide it should do something, that can 
be re-introduced.   It's always easier to unlock a dead end with a well thought 
out approach, than to make multiple, small modifications to an existing 
behavior.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.