sqlalchemy.orm.query.Query.get returns the wrong result if querying for a single field
Issue #2144
resolved
The following code returns (x,):
return session.query(Model.x).get(1)
However, the following code returns an instance of the Model:
session.query(Model).get(1)
return session.query(Model.x).get(1)
This is confusing and can cause errors. The documentation (http://www.sqlalchemy.org/docs/orm/query.html?highlight=get#sqlalchemy.orm.query.Query.get) does not specify that querying for Model.x will not work.
Comments (3)
-
repo owner -
repo owner odd that the docstring still doesnt talk about the identity map. added
#2146for that -
repo owner - removed milestone
Removing milestone: 0.6.8 (automated comment)
- Log in to comment
query(column).get() is not the correct usage of get(). This should be implied by the understanding that get() is retrieving the object directly from the identity map, but the error in this specific usage is documented in the changesets referenced below. This specific usage now raises an error in 0.7 and emits a deprecation warning in 0.6.8 for existing code that might be relying upon it.
b80ce42509f803c60967900a21320b4957a989c9 eb569b672bada027f5cfe7c918c91affeb9c61b0
documentation as a separate checkin:
e500b445209f33e162d585eb15a9f8f045b1d01b 0c1c6431bc64d98c0bfd517795e2965d32f0968a