]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- It is an error to call query.get() when the
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Apr 2011 22:33:55 +0000 (18:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Apr 2011 22:33:55 +0000 (18:33 -0400)
given entity is not a single, full class
entity or mapper (i.e. a column).  This is
a deprecation warning in 0.6.8.
[ticket:2144]

CHANGES
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql/compiler.py
test/orm/test_query.py

diff --git a/CHANGES b/CHANGES
index faa02e86eec4760dae9c0199ffc286619ea97157..54744b5a9a1963f6adcdcd8874e43f5f8260b852 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,12 @@ CHANGES
     fixed up some of the error messages tailored
     in [ticket:2069]
 
+  - It is an error to call query.get() when the
+    given entity is not a single, full class 
+    entity or mapper (i.e. a column).  This is
+    a deprecation warning in 0.6.8.  
+    [ticket:2144]
+
 - sql
   - Added explicit check for when Column .name
     is assigned as blank string [ticket:2140]
index 07df0de42967e4cdf7d2a8b09ccdee8875e02a7a..b7b2eccec850651dd923f33691b9f67de63446a7 100644 (file)
@@ -298,6 +298,18 @@ class Query(object):
                 )
         return self._mapper_zero()
 
+    def _only_full_mapper_zero(self, methname):
+        if len(self._entities) != 1:
+            raise sa_exc.InvalidRequestError(
+                    "%s() can only be used against "
+                    "a single mapped class." % methname)
+        entity = self._entity_zero()
+        if not hasattr(entity, 'primary_entity'):
+            raise sa_exc.InvalidRequestError(
+                    "%s() can only be used against "
+                    "a single mapped class." % methname)
+        return entity.entity_zero
+
     def _only_entity_zero(self, rationale=None):
         if len(self._entities) > 1:
             raise sa_exc.InvalidRequestError(
@@ -631,9 +643,7 @@ class Query(object):
 
         ident = util.to_list(ident)
 
-        mapper = self._only_mapper_zero(
-                    "get() can only be used against a single mapped class."
-                )
+        mapper = self._only_full_mapper_zero("get")
 
         if len(ident) != len(mapper.primary_key):
             raise sa_exc.InvalidRequestError(
index 82c1748ccda47f853ea9a5f9688bddf7866baf3c..829adebac0f3f2fd98b11055d2a3f4afa0ef28cf 100644 (file)
@@ -965,7 +965,7 @@ class SQLCompiler(engine.Compiled):
         if colparams or not supports_default_values:
             text += " (%s)" % ', '.join([preparer.format_column(c[0])
                        for c in colparams])
-
+        
         if self.returning or insert_stmt._returning:
             self.returning = self.returning or insert_stmt._returning
             returning_clause = self.returning_clause(
index 93f349ff29060f203a4ba1372553a9e5bb836487..a87e1398a59626512f404dd79c4f96624a2be93d 100644 (file)
@@ -189,6 +189,13 @@ class GetTest(QueryTest):
         q = s.query(CompositePk)
         assert_raises(sa_exc.InvalidRequestError, q.get, (7, 10, 100))
 
+    def test_get_against_col(self):
+        User = self.classes.User
+
+        s = Session()
+        q = s.query(User.id)
+        assert_raises(sa_exc.InvalidRequestError, q.get, (5, ))
+
     def test_get_null_pk(self):
         """test that a mapping which can have None in a 
         PK (i.e. map to an outerjoin) works with get()."""