Mike Bayer avatar Mike Bayer committed 2177c41

- Calling query.get() against a column-based entity is
invalid, this condition now raises a deprecation warning.
[ticket:2144]

Comments (0)

Files changed (5)

 =======
 CHANGES
 =======
+0.6.8
+=====
+- orm
+  - Calling query.get() against a column-based entity is
+    invalid, this condition now raises a deprecation warning.
+    [ticket:2144]
+
 0.6.7
 =====
 - orm
     inside to the outside query if from_self()
     were used. [ticket:2130].
 
+  - 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
   - Column.copy(), as used in table.tometadata(), copies the 
     'doc' attribute.  [ticket:2028]

lib/sqlalchemy/__init__.py

 __all__ = sorted(name for name, obj in locals().items()
                  if not (name.startswith('_') or inspect.ismodule(obj)))
 
-__version__ = '0.6.7'
+__version__ = '0.6.8'
 
 del inspect, sys

lib/sqlalchemy/orm/query.py

                 )
         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'):
+            util.warn("Calling %s() with a "
+                    "column-based entity is deprecated." % 
+                    methname)
+        return entity.entity_zero
+
     def _only_entity_zero(self, rationale=None):
         if len(self._entities) > 1:
             raise sa_exc.InvalidRequestError(
         if hasattr(ident, '__composite_values__'):
             ident = ident.__composite_values__()
 
-        key = self._only_mapper_zero(
-                    "get() can only be used against a single mapped class."
+        key = self._only_full_mapper_zero("get"
                 ).identity_key_from_primary_key(ident)
         return self._get(key, ident)
 

lib/sqlalchemy/sql/compiler.py

         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(insert_stmt, self.returning)

test/orm/test_query.py

         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.SAWarning, 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()."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.