From: Mike Bayer Date: Fri, 22 Apr 2011 22:32:37 +0000 (-0400) Subject: - Calling query.get() against a column-based entity is X-Git-Tag: rel_0_6_8~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b80ce42509f803c60967900a21320b4957a989c9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Calling query.get() against a column-based entity is invalid, this condition now raises a deprecation warning. [ticket:2144] --- diff --git a/CHANGES b/CHANGES index ec6ebb38e0..6c25ec7a40 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,13 @@ ======= 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 @@ -60,6 +67,12 @@ CHANGES 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] diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 8de20805fb..ae88787626 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -115,6 +115,6 @@ from sqlalchemy.engine import create_engine, engine_from_config __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 diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 7f3af5a023..f8b45cdb65 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -302,6 +302,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'): + 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( @@ -631,8 +643,7 @@ class Query(object): 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) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index ed06e32c90..a2ead6a4d4 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -875,7 +875,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(insert_stmt, self.returning) diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 8c30b8c8dc..43a415fde6 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -164,6 +164,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.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()."""